rustlings

solving rustlings ft. dracuxan
git clone [email protected]:dracuxan/rustlings.git
Log | Files | Refs

traits5.rs (756B)


      1 trait SomeTrait {
      2     fn some_function(&self) -> bool {
      3         true
      4     }
      5 }
      6 
      7 trait OtherTrait {
      8     fn other_function(&self) -> bool {
      9         true
     10     }
     11 }
     12 
     13 struct SomeStruct;
     14 impl SomeTrait for SomeStruct {}
     15 impl OtherTrait for SomeStruct {}
     16 
     17 struct OtherStruct;
     18 impl SomeTrait for OtherStruct {}
     19 impl OtherTrait for OtherStruct {}
     20 
     21 // TODO: Fix the compiler error by only changing the signature of this function.
     22 fn some_func(item: impl OtherTrait + SomeTrait) -> bool {
     23     item.some_function() && item.other_function()
     24 }
     25 
     26 fn main() {
     27     // You can optionally experiment here.
     28 }
     29 
     30 #[cfg(test)]
     31 mod tests {
     32     use super::*;
     33 
     34     #[test]
     35     fn test_some_func() {
     36         assert!(some_func(SomeStruct));
     37         assert!(some_func(OtherStruct));
     38     }
     39 }