From e7c14ea67e4a39789e7c1dd3a264c61a9c14050e Mon Sep 17 00:00:00 2001 From: Hunter Kvalevog Date: Sun, 27 Sep 2026 15:47:45 -0500 Subject: rustlings: complete 15 --- rustlings/solutions/15_traits/traits5.rs | 39 ++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'rustlings/solutions/15_traits/traits5.rs') diff --git a/rustlings/solutions/15_traits/traits5.rs b/rustlings/solutions/15_traits/traits5.rs index dcf2377..1fb426a 100644 --- a/rustlings/solutions/15_traits/traits5.rs +++ b/rustlings/solutions/15_traits/traits5.rs @@ -1,4 +1,39 @@ +trait SomeTrait { + fn some_function(&self) -> bool { + true + } +} + +trait OtherTrait { + fn other_function(&self) -> bool { + true + } +} + +struct SomeStruct; +impl SomeTrait for SomeStruct {} +impl OtherTrait for SomeStruct {} + +struct OtherStruct; +impl SomeTrait for OtherStruct {} +impl OtherTrait for OtherStruct {} + +fn some_func(item: impl SomeTrait + OtherTrait) -> bool { + // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + item.some_function() && item.other_function() +} + fn main() { - // DON'T EDIT THIS SOLUTION FILE! - // It will be automatically filled after you finish the exercise. + // You can optionally experiment here. +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_some_func() { + assert!(some_func(SomeStruct)); + assert!(some_func(OtherStruct)); + } } -- cgit v1.2.3