diff options
| author | mo8it <mo8it@proton.me> | 2024-06-27 12:23:33 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-06-27 12:23:33 +0200 |
| commit | c0452d160b889b3686409820192797d9e9f9cad7 (patch) | |
| tree | a2d958597268f396c401a619e7b72739479466d1 /solutions/15_traits/traits4.rs | |
| parent | b4b7ae63ada9128d4798d301cfc757a60904c6b8 (diff) | |
traits4 solution
Diffstat (limited to 'solutions/15_traits/traits4.rs')
| -rw-r--r-- | solutions/15_traits/traits4.rs | 35 |
1 files changed, 34 insertions, 1 deletions
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)); + } +} |
