Last active
May 2, 2016 12:08
-
-
Save bugaevc/512d6cc8641d8d5786005f7043697e4f 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
// this does not compile | |
fn middle_name(full_name: &str) -> &str { | |
full_name.split_whitespace().nth(1).unwrap() | |
} | |
fn main() { | |
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