Created
August 21, 2019 00:19
-
-
Save rust-play/520c8d1a86e0070d33b9cf2e826a232b to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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 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