Skip to content

Instantly share code, notes, and snippets.

@eyelash
Created May 21, 2017 14:03
Show Gist options
  • Select an option

  • Save eyelash/133a11066e47cd4e4dca36e804943afd to your computer and use it in GitHub Desktop.

Select an option

Save eyelash/133a11066e47cd4e4dca36e804943afd to your computer and use it in GitHub Desktop.
fn get_longest(v: &[String]) -> &str {
assert!(v.len() > 0);
let mut result = &v[0];
for s in v {
if s.len() > result.len() {
result = &s
}
}
result.as_str()
}
fn foo(v: &mut Vec<String>) {
let longest = get_longest(v);
if longest != "longest" {
let longest = format!("{} (longest)", longest.len());
v.push(longest);
}
}
fn main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment