Skip to content

Instantly share code, notes, and snippets.

@mod7ex
Created March 14, 2023 22:47
Show Gist options
  • Save mod7ex/101d8789ffc61cabf8af063512fbda88 to your computer and use it in GitHub Desktop.
Save mod7ex/101d8789ffc61cabf8af063512fbda88 to your computer and use it in GitHub Desktop.
Borrow checker in rust
fn main() {
let mut s1 = String::from("Hello");
let s2 = &mut s1;
s2.push('!');
// change order of next tow lines and program will not compile
println!("s2 :{}", s2);
println!("s1 :{}", s1);
s2.push('.'); // comment this line to to make program compile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment