From c0452d160b889b3686409820192797d9e9f9cad7 Mon Sep 17 00:00:00 2001 From: mo8it Date: Thu, 27 Jun 2024 12:23:33 +0200 Subject: traits4 solution --- solutions/15_traits/traits4.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'solutions/15_traits') diff --git a/solutions/15_traits/traits4.rs b/solutions/15_traits/traits4.rs index 4e18198..78b5a11 100644 --- a/solutions/15_traits/traits4.rs +++ b/solutions/15_traits/traits4.rs @@ -1 +1,34 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +trait Licensed { + fn licensing_info(&self) -> String { + "Default license".to_string() + } +} + +struct SomeSoftware; +struct OtherSoftware; + +impl Licensed for SomeSoftware {} +impl Licensed for OtherSoftware {} + +fn compare_license_types(software1: impl Licensed, software2: impl Licensed) -> bool { + software1.licensing_info() == software2.licensing_info() +} + +fn main() { + // You can optionally experiment here. +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn compare_license_information() { + assert!(compare_license_types(SomeSoftware, OtherSoftware)); + } + + #[test] + fn compare_license_information_backwards() { + assert!(compare_license_types(OtherSoftware, SomeSoftware)); + } +} -- cgit v1.2.3