How to do it...

Perform the following step:

  1. Create a file named binding.rs and enter a code snippet that includes declaring the main function and different variables:
        fn main() {
// Simplest variable binding
let a = 5;
// pattern
let (b, c) = (1, 2);
// type annotation
let x_val: i32 = 5;
// shadow example
let y_val: i32 = 8;
{
println!("Value assigned when entering the
scope : {}", y_val); // Prints "8".
let y_val = 12;
println!("Value modified within scope :{}", y_val);
// Prints "12".
}
println!("Value which was assigned first : {}", y_val);
// Prints "8".
let y_val = 42;
println!("New value assigned : {}", y_val);
//Prints "42".
}

You should get the following screenshot as output upon running the preceding code:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.99.71