Created
July 25, 2019 01:23
-
-
Save umran/facc330c994a4b792b0c2d3b7b492cd5 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
fn main() { | |
// create a new String | |
let mut original_string = String::from("Toulouse"); | |
{ | |
// create a mutable (mut) variable that mutably (&mut) borrows the original String | |
let mut first_reference = &mut original_string; | |
// create another variable that mutably (&mut) borrows the previously created reference | |
let second_reference = &mut first_reference; | |
// dereference (*) the second variable twice (**), once to point back to the first reference | |
// and once more to point back to the original string, and assign a new String | |
**second_reference = String::from("Miami"); | |
} | |
// assert that the original string has changed its value | |
assert_eq!(original_string, String::from("Miami")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment