Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 21, 2019 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/520c8d1a86e0070d33b9cf2e826a232b to your computer and use it in GitHub Desktop.
Save rust-play/520c8d1a86e0070d33b9cf2e826a232b to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
let a = find_min(vec![-9, 1, 2, 3, 4]);
let b = find_min(vec![100, 10, 20, 30, 40]);
println!("{:?} {:?}", a, b);
}
fn find_min<T>(data: Vec<T>) -> Option<T> {
let mut it = data.into_iter();
let mut min = match it.next() {
Some(elem) => elem,
None => return None,
};
for elem in it {
if elem < min {
min = elem;
}
}
Some(min)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment