From 1f926b4358c3e8ffd79d289bd5ec56a5a1c57b00 Mon Sep 17 00:00:00 2001 From: Rock070 Date: Wed, 3 Jan 2024 00:28:39 +0800 Subject: [PATCH] Refactor compare_license_types function --- exercises/15_traits/traits4.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/exercises/15_traits/traits4.rs b/exercises/15_traits/traits4.rs index 4bda3e57..d9a3428b 100644 --- a/exercises/15_traits/traits4.rs +++ b/exercises/15_traits/traits4.rs @@ -23,7 +23,23 @@ impl Licensed for SomeSoftware {} impl Licensed for OtherSoftware {} // YOU MAY ONLY CHANGE THE NEXT LINE -fn compare_license_types(software: ??, software_two: ??) -> bool { + +// 1. straight foreword +// fn compare_license_types(software: impl Licensed, software_two: impl Licensed) -> bool { +// software.licensing_info() == software_two.licensing_info() +// } + +// 2. trait bound +// fn compare_license_types(software: T, software_two: P) -> bool { +// software.licensing_info() == software_two.licensing_info() +// } + + +// 3. trait bound + where clause +fn compare_license_types(software: T, software_two: P) -> bool + where T: Licensed, + P: Licensed +{ software.licensing_info() == software_two.licensing_info() }