Skip to content

Instantly share code, notes, and snippets.

@umran
Created July 25, 2019 01:23
Show Gist options
  • Save umran/facc330c994a4b792b0c2d3b7b492cd5 to your computer and use it in GitHub Desktop.
Save umran/facc330c994a4b792b0c2d3b7b492cd5 to your computer and use it in GitHub Desktop.
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