Created
April 5, 2016 01:36
-
-
Save kscz/ed087571afe2c94501eb7e44182e0f90 to your computer and use it in GitHub Desktop.
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 = String::from("What is love?"); | |
let y = String::from("Baby don't hurt me,"); | |
let ref_y = print_first_return_second(&x, &y); | |
print!("{}", y); | |
print!("{}", ref_y); | |
take_ownership(x); // This is okay, no one is borrowing x | |
} | |
fn print_first_return_second<'a, 'b>(print_me: &'a str, return_me: &'b str) -> &'b str { | |
println!("{}", print_me); | |
&return_me[4..] | |
} | |
fn take_ownership(of_this: String) -> () { | |
println!(" no more!"); | |
// of_this will be deleted! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment