Created
July 30, 2014 15:50
-
-
Save MatejLach/f9d12f3cbe4859f16925 to your computer and use it in GitHub Desktop.
An example of borrowing using references in Rust...
This file contains hidden or 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() { | |
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