Skip to content

Instantly share code, notes, and snippets.

@jcar787
Created April 14, 2022 23:15
Show Gist options
  • Save jcar787/9c71e7dcdd8c0c39dcb62dcf780a92ec to your computer and use it in GitHub Desktop.
Save jcar787/9c71e7dcdd8c0c39dcb62dcf780a92ec to your computer and use it in GitHub Desktop.
Losing ownership to a function (no borrowing) in rust
fn give_me_your_name(name: String) {
println!("Look at me, this is my name now! {}", name);
}
fn main() {
let my_name = String::from("Jeff");
give_me_your_name(my_name);
// Uncomment the next line and its gonna give you an error
// println!("This was my name: {}, my_name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment