Learn how to define variables in Rust.
In Rust, variables are defined using the let
keyword.
let team_name = "Rustaceans";
In Rust, variables are defined using the let
keyword.
let team_name = "Rustaceans";
By default, Rust variables are immutable.
Once defined, its value can't be changed.
let team_name = "Rustaceans";
team_name = "Crustaceans"; // This raises an error!
The mut
keyword can be used to define a variable that can change, i.e. a "mutable" variable.
let team_name = "Rustaceans";
team_name = "Crustaceans"; // This raises an error!
let mut mutable_team_name = "Rustaceans";
mutable_team_name = "Crustaceans"; // This doesn't error
In this concept, we learned about the following:
Variables: The let
keyword is used to define variables. Variables are immutable by default.
Mutability: The mut
keyword is used to make variables mutable.
You can learn more about this in the Variables and Mutability chapter of the Rust book.