Last active
May 2, 2016 12:06
-
-
Save bugaevc/e92a86c585328a316937d76c16c0f634 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 the_longest<'a>(s1: &'a str, s2: &'a str) -> &'a str { | |
if s1.len() > s2.len() { s1 } else { s2 } | |
} | |
fn main() { | |
let s1 = String::from("Python"); | |
// explicitly borrowing to ensure that | |
// the borrow lasts longer than s2 exists | |
let s1_b = &s1; | |
{ | |
let s2 = String::from("C"); | |
let res = the_longest(s1_b, &s2); | |
println!("{} is the longest if you judge by name", res); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment