Compare commits

...

2 Commits

Author SHA1 Message Date
6d6e600720
RBE more variable bindings fun 2021-10-06 19:40:31 -04:00
d2563484f9
RBE variable bindings mutability 2021-09-29 11:38:53 -04:00
5 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,19 @@
fn main() {
let a_binding;
{
let x = 2;
a_binding = x * x;
}
println!("a binding: {}", a_binding);
let another_binding;
//println!("another binding: {}", another_binding);
another_binding = 1;
println!("another binding: {}", another_binding);
}

View File

@ -0,0 +1,11 @@
fn main() {
let mut _mutable_integer = 7i32;
{
let _mutable_integer = _mutable_integer;
// _mutable_integer = 50;
}
_mutable_integer = 3;
}

View File

@ -0,0 +1,12 @@
fn main() {
let _immutable_binding = 1;
let mut mutable_binding = 1;
println!("Before mutation: {}", mutable_binding);
mutable_binding += 1;
println!("After mutation: {}", mutable_binding);
// _immutable_binding += 1;
}

View File

@ -0,0 +1,12 @@
fn main() {
let long_lived_binding = 1;
{
let short_lived_binding = 2;
println!("inner short: {}", short_lived_binding);
}
// println!("outer short: {}", short_lived_binding);
println!("outer long: {}", long_lived_binding);
}

View File

@ -0,0 +1,16 @@
fn main() {
let shadowed_binding = 1;
{
println!("before being shadowed: {}", shadowed_binding);
let shadowed_binding = "abc";
println!("shadowed in inner block: {}", shadowed_binding);
}
println!("outside inner block: {}", shadowed_binding);
let shadowed_binding = 2;
println!("shadowed in outer block: {}", shadowed_binding);
}