Last active
December 25, 2019 23:11
-
-
Save kscz/0a56dc848dc2b0e0ecf9efe8331b7f8b 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("Mysterious first letter!"); | |
| let ref_x = first_letter(&x); | |
| take_ownership(x); // ERROR: ref_x still exists and is "borrowing" x | |
| // We can't delete x safely! | |
| println!("{}ystery solved!", ref_x); | |
| } | |
| fn first_letter(input: &str) -> &str { | |
| &input[0..1] | |
| } | |
| fn take_ownership(of_this: String) -> () { | |
| println!("I will destroy you: \"{}\"", of_this); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment