MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / main

Function main

01_numbers/rust/scope.rs:1–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1fn main() {
2
3 // scope
4 // This binding lives in the main function
5 let long_lived_binding = 1;
6
7 // This is a block, and has a smaller scope than the main function
8 {
9 // This binding only exists in this block
10 let short_lived_binding = 2;
11
12 println!("inner short: {}", short_lived_binding);
13
14 // This binding *shadows* the outer one
15 let long_lived_binding = 5_f32;
16
17 println!("inner long: {}", long_lived_binding);
18 }
19 // End of the block
20
21 // Error! `short_lived_binding` doesn't exist in this scope
22 println!("outer short: {}", short_lived_binding);
23
24 println!("outer long: {}", long_lived_binding);
25
26 // This binding also *shadows* the previous binding
27 let long_lived_binding = 'a';
28
29 println!("outer long: {}", long_lived_binding);
30}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected