See the functions: fn min() and fn fold().
Another option, not necessarily the most efficient.
"Folding is useful whenever you have a collection of something, and want to produce a single value from it."
fn main() {
let values: Vec<i32> = vec![5, 6, 8, 4, 2, 7];
// The empty vector must be filtered beforehand!
// let values: Vec<i32> = vec![]; // Not work!!!
// Get the minimum value without being wrapped by Option<T>
let min_value: i32 = values
.iter()
//.into_iter()
//.fold(i32::MAX, i32::min);
.fold(i32::MAX, |arg0: i32, other: &i32| i32::min(arg0, *other));
println!("values: {values:?}");
println!("min_value: {min_value}");
assert_eq!(min_value, 2);
}
See Rust Playground