Created
March 14, 2023 22:47
-
-
Save mod7ex/101d8789ffc61cabf8af063512fbda88 to your computer and use it in GitHub Desktop.
Borrow checker in rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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