Last active
March 9, 2019 02:50
-
-
Save kunigami/ccdd7ff628a6e286e6163e5ca8a490f8 to your computer and use it in GitHub Desktop.
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
let mut vec1 = vec![1, 2, 3]; | |
// Performing changes is okay. vec1 is mutable | |
vec1.push(4); | |
// Assignment -> transferring ownership from vec1 to vec2 | |
// This is the end of scope for vec1. | |
let mut vec2 = vec1; | |
// Error: vec1 cannot be read from/written to | |
println!("{}", vec1.len()); | |
// vec2 can still perform further mutations | |
vec2.push(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment