Skip to content

Instantly share code, notes, and snippets.

@bugaevc
Last active May 2, 2016 12:06
Show Gist options
  • Save bugaevc/e92a86c585328a316937d76c16c0f634 to your computer and use it in GitHub Desktop.
Save bugaevc/e92a86c585328a316937d76c16c0f634 to your computer and use it in GitHub Desktop.
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