Hi guys,
I'm trying to do seemingly the simplest thing in the world, extracting the lexicographically first string in a list, what I've got at this time works but is so unwieldy, there has to be a better way!
fn main() {
let strings: Vec<String> = vec!("first".to_string(), "second".to_string());
let mut min: Option<String> = None;
for st in strings {
// More computation here, cannot use .map() or the like
if &st < min.as_ref().unwrap_or(&String::from("~")) { // so ugly, all I wanted was "st < min" :-(
min = Some(st.to_string());
}
}
println!("{:?}", min);
}
Output:
Some("first")
Thanks for any suggestion!
Chris