Declaring and manipulating variables in programming is a fundamental concept that allows you to store and modify data. Variables in Rust are immutable by default, but you can make them mutable using the mut
keyword.
In this challenge, you will declare and use mutable variables in Rust. You will be given a function where you need to declare variables, modify their values, and perform specific operations.
text
with any initial value of type String
Use let mut
to make it mutable.text
to something else of your choice.mutates_value(&mut text)
function, which will change the value of your text
variable.If you're stuck, feel free to check out the hints below
Use the let mut
keyword to declare a mutable variable.
To give the value to as a mutable reference use the &mut
keyword. e.g.
To create a String
from a &str
, use String::from(value)
or value.to_string()
. e.g.
To return a value from a function, either use the return
statement or let the last expression be the return value. For example: