Storing all values in constants is not an option. It is not good because constants live as long as the program and moreover can't change, and often we want to change values. In Rust, we can bind a value to a variable by using a let binding.
// see Chapter 2/code/bindings.rs fn main() { let energy = 5; // value 5 is bound to variable energy }
Unlike in many other languages, such as Python or Go, the semicolon,;, is needed here to end the statement. Otherwise, the compiler throws an error, as follows:
error: expected one of `.`, `;`, or an operator, found `}`
We also want to create bindings only when they are used in the rest of the program, but don't worry, the Rust compiler warns us about that. The warning looks like the following:
values.rs:2:6: 2:7 warning: unused variable: `energy`, #[warn(unused_variables)] on by default ...