Skip to content

Instantly share code, notes, and snippets.

@MatejLach
Created July 30, 2014 15:50
Show Gist options
  • Save MatejLach/f9d12f3cbe4859f16925 to your computer and use it in GitHub Desktop.
Save MatejLach/f9d12f3cbe4859f16925 to your computer and use it in GitHub Desktop.
An example of borrowing using references in Rust...
fn main() {
let x = box 5i; // Creates a box
let y = x; // Transfers ownership to "y"
let x = &y; // "x" now references what "y" owns
println!("{}", x); // This will compile successfully
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment