rustlings

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

traits3.rs (1114B)


      1 trait Licensed {
      2     // TODO: Add a default implementation for `licensing_info` so that
      3     // implementors like the two structs below can share that default behavior
      4     // without repeating the function.
      5     // The default license information should be the string "Default license".
      6     fn licensing_info(&self) -> String {
      7         String::from("Default license")
      8     }
      9 }
     10 
     11 struct SomeSoftware {
     12     version_number: i32,
     13 }
     14 
     15 struct OtherSoftware {
     16     version_number: String,
     17 }
     18 
     19 impl Licensed for SomeSoftware {} // Don't edit this line.
     20 impl Licensed for OtherSoftware {} // Don't edit this line.
     21 
     22 fn main() {
     23     // You can optionally experiment here.
     24 }
     25 
     26 #[cfg(test)]
     27 mod tests {
     28     use super::*;
     29 
     30     #[test]
     31     fn is_licensing_info_the_same() {
     32         let licensing_info = "Default license";
     33         let some_software = SomeSoftware { version_number: 1 };
     34         let other_software = OtherSoftware {
     35             version_number: "v2.0.0".to_string(),
     36         };
     37         assert_eq!(some_software.licensing_info(), licensing_info);
     38         assert_eq!(other_software.licensing_info(), licensing_info);
     39     }
     40 }