练习:通用 min 函数

In this short exercise, you will implement a generic min function that determines the minimum of two values, using the Ord trait.

  1. use std::cmp::Ordering;
  2. // TODO: implement the `min` function used in `main`.
  3. fn main() {
  4. assert_eq!(min(0, 10), 0);
  5. assert_eq!(min(500, 123), 123);
  6. assert_eq!(min('a', 'z'), 'a');
  7. assert_eq!(min('7', '1'), '1');
  8. assert_eq!(min("hello", "goodbye"), "goodbye");
  9. assert_eq!(min("bat", "armadillo"), "armadillo");
  10. }

This slide and its sub-slides should take about 10 minutes.