As I was trying to figure out how to get the minimum and maximum value from a vector I bumped into the min and max functions that work on two values and can tell use which is the smaller and which is the bigger value.
In this example you can see them working on integers and on strings.
fn main() {
let x = 3;
let y = 5;
let min = std::cmp::min(x, y);
println!("min: {}", min);
let max = std::cmp::max(x, y);
println!("max: {}", max);
let x = "hello".to_string();
let y = "world".to_string();
let min = std::cmp::min(&x, &y);
println!("min: {}", min);
let max = std::cmp::max(x, y);
println!("max: {}", max);
}
min: 3
max: 5
min: hello
max: world