A binding gives a name to a value so the program can use that value later. In Rust, let creates a binding such as my_number for 8. The name helps you remember what the data represents. section 1.7 section 1.2
A Rust binding follows a few practical rules:
- Its lifetime is limited to the surrounding code block, or scope. A binding created inside a nested block cannot be used after that block ends. section 1.6 section 1.7
- A block can return a value, allowing an outer binding to receive the result even though the inner binding disappears. section 1.7
- Bindings are immutable unless declared with mut. Shadowing instead creates another binding with the same name. section 1.12
- Rust often infers a binding's type, though you can provide the type name explicitly. section 1.0 section 1.12
A binding from a block
let my_number = { let second_number = 8; second_number + 9 }; println!("My number is: {}", my_number); section 1.7
fn main() {
{
let my_number = 8; #1
}
println!("Hello, number {}", my_number); #2
}
Compare the nested binding's scope with the later use of my_number; the compiler rejects a name after its block has ended. section 1.7










