Skip to content

Instantly share code, notes, and snippets.

@CodeSandwich
Created March 26, 2018 12:39
Show Gist options
  • Save CodeSandwich/5dcd92b946dc72fdae03352bd45ec9d6 to your computer and use it in GitHub Desktop.
Save CodeSandwich/5dcd92b946dc72fdae03352bd45ec9d6 to your computer and use it in GitHub Desktop.
fn borrow_outlives_value() -> &String {
let value = "abc".to_string(); // crate value
let borrow = &value; // create borrow
return borrow // borrow is not deleted
// <COMPILE TIME FAIL> delete value,
// but it's still borrowed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment