Last active
December 25, 2019 23:15
-
-
Save kscz/7bd815dfbaac467cd48ce10512b44c5d 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); | |
take_ownership(y); // ERROR: ref_y is borrowing y! We can't delete y! | |
print!("{}", ref_y); | |
} | |
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