3 fn test_generic<T, F>(expected: T, not_expected: T, eq: F) where
5 F: FnOnce(T, T) -> bool,
7 let actual: T = if true { expected.clone() } else { not_expected };
8 assert!(eq(expected, actual));
12 fn compare_bool(b1: bool, b2: bool) -> bool { return b1 == b2; }
13 test_generic::<bool, _>(true, false, compare_bool);
23 fn compare_rec(t1: Pair, t2: Pair) -> bool {
24 t1.a == t2.a && t1.b == t2.b
26 test_generic::<Pair, _>(Pair{a: 1, b: 2}, Pair{a: 2, b: 3}, compare_rec);
29 pub fn main() { test_bool(); test_rec(); }