Rust deviates from the mainstream here by making constants the default variable type. If you need a variable that can be mutated, you use the let mut keyword:
// variables.rs fn main() { let mut target = "world"; println!("Howdy, {}", target); target = "mate"; println!("Howdy, {}", target); }
Conditionals should also look familiar; they follow the C-like if...else pattern. Since Rust is strongly-typed, the condition must be a Boolean type:
// conditionals.rs fn main() { let condition = true; if condition { println!("Condition was true"); } else { println!("Condition was false"); } }
In Rust, if is not a statement but an expression. This distinction means that if always returns a value. The value may be ...