Skip to content

Instantly share code, notes, and snippets.

@kscz
Last active December 25, 2019 23:15
Show Gist options
  • Save kscz/7bd815dfbaac467cd48ce10512b44c5d to your computer and use it in GitHub Desktop.
Save kscz/7bd815dfbaac467cd48ce10512b44c5d to your computer and use it in GitHub Desktop.
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