Skip to content

Instantly share code, notes, and snippets.

@ford-prefect
Created March 29, 2017 13:37
Show Gist options
  • Save ford-prefect/7dd17f703bdd8abd0f09c674fa02af2c to your computer and use it in GitHub Desktop.
Save ford-prefect/7dd17f703bdd8abd0f09c674fa02af2c to your computer and use it in GitHub Desktop.
fn largest<T: PartialOrd>(list: &[T]) -> &T {
let mut largest = &list[0];
for i in list.iter() {
if largest < i {
largest = i;
}
}
largest
}
fn main() {
let v = vec![1, 5, 4, 3, 2];
println!("Hello, world! {}", largest(&v));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment