From 599d634ee2277d1071dd803346993c24ab13462b Mon Sep 17 00:00:00 2001 From: Sam White Date: Fri, 25 Feb 2022 16:41:10 +0000 Subject: [PATCH] feat: Add traits4.rs exercise --- exercises/traits/traits4.rs | 44 +++++++++++++++++++++++++++++++++++++ info.toml | 11 ++++++++++ 2 files changed, 55 insertions(+) create mode 100644 exercises/traits/traits4.rs diff --git a/exercises/traits/traits4.rs b/exercises/traits/traits4.rs new file mode 100644 index 0000000..cc5fe16 --- /dev/null +++ b/exercises/traits/traits4.rs @@ -0,0 +1,44 @@ +// traits4.rs +// +// Your task is to replace the '??' sections so the code compiles. +// Don't change any line other than 21. + +// I AM NOT DONE + +pub trait Licensed { + fn licensing_info(&self) -> String { + "some information".to_string() + } +} + +struct SomeSoftware {} + +struct OtherSoftware {} + +impl Licensed for SomeSoftware {} +impl Licensed for OtherSoftware {} + +fn compare_license_types(software: ??, software_two: ??) -> bool { + software.licensing_info() == software_two.licensing_info() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn compare_license_information() { + let some_software = SomeSoftware {}; + let other_software = OtherSoftware {}; + + assert!(compare_license_types(some_software, other_software)); + } + + #[test] + fn compare_license_information_backwards() { + let some_software = SomeSoftware {}; + let other_software = OtherSoftware {}; + + assert!(compare_license_types(other_software, some_software)); + } +} diff --git a/info.toml b/info.toml index 971f515..2ad9a0e 100644 --- a/info.toml +++ b/info.toml @@ -716,6 +716,17 @@ implement the function themselves. See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#default-implementations """ +[[exercises]] +name = "traits4" +path = "exercises/traits/traits4.rs" +mode = "test" +hint = """ +Instead of using concrete types as parameters you can use traits. Try replacing the +'??' with 'impl ' + +See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters +""" + # QUIZ 3 [[exercises]]