演習: ジェネリックな min
この短い演習では、Ord トレイトを使って 2 つの値の最小値を 決定するジェネリックな min 関数を実装します。
// Copyright 2023 Google LLC // SPDX-License-Identifier: Apache-2.0 use std::cmp::Ordering; // TODO: テストで使用される `min` 関数を実装する。 #[test] fn integers() { assert_eq!(min(0, 10), 0); assert_eq!(min(500, 123), 123); } #[test] fn chars() { assert_eq!(min('a', 'z'), 'a'); assert_eq!(min('7', '1'), '1'); } #[test] fn strings() { assert_eq!(min("hello", "goodbye"), "goodbye"); assert_eq!(min("bat", "armadillo"), "armadillo"); }