traits4.rs (818B)
1 trait Licensed { 2 fn licensing_info(&self) -> String { 3 "Default license".to_string() 4 } 5 } 6 7 struct SomeSoftware; 8 struct OtherSoftware; 9 10 impl Licensed for SomeSoftware {} 11 impl Licensed for OtherSoftware {} 12 13 // TODO: Fix the compiler error by only changing the signature of this function. 14 fn compare_license_types(software1: impl Licensed, software2: impl Licensed) -> bool { 15 software1.licensing_info() == software2.licensing_info() 16 } 17 18 fn main() { 19 // You can optionally experiment here. 20 } 21 22 #[cfg(test)] 23 mod tests { 24 use super::*; 25 26 #[test] 27 fn compare_license_information() { 28 assert!(compare_license_types(SomeSoftware, OtherSoftware)); 29 } 30 31 #[test] 32 fn compare_license_information_backwards() { 33 assert!(compare_license_types(OtherSoftware, SomeSoftware)); 34 } 35 }