Last active
May 2, 2016 12:07
-
-
Save bugaevc/298d50becfc609208565516791d658e9 to your computer and use it in GitHub Desktop.
This file contains 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 middle_name<'a>(full_name: &'a str) -> &'a str { | |
full_name.split_whitespace().nth(1).unwrap() | |
} | |
fn main() { | |
let name = String::from("Harry James Potter"); | |
let res = middle_name(&name); | |
assert_eq!(res, "James"); | |
// won't compile: | |
/* | |
let res; | |
{ | |
let name = String::from("Harry James Potter"); | |
res = middle_name(&name); | |
} | |
assert_eq!(res, "James"); | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment