Solution

  1. use std::cmp::Ordering;
  2. fn min<T: Ord>(l: T, r: T) -> T {
  3.     match l.cmp(&r) {
  4.         Ordering::Less | Ordering::Equal => l,
  5.         Ordering::Greater => r,
  6.     }
  7. }
  8. fn main() {
  9.     assert_eq!(min(0, 10), 0);
  10.     assert_eq!(min(500, 123), 123);
  11.     assert_eq!(min('a', 'z'), 'a');
  12.     assert_eq!(min('7', '1'), '1');
  13.     assert_eq!(min("hello", "goodbye"), "goodbye");
  14.     assert_eq!(min("bat", "armadillo"), "armadillo");
  15. }