rustlings

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

generics2.rs (431B)


      1 struct Wrapper<T> {
      2     value: T,
      3 }
      4 
      5 impl<T> Wrapper<T> {
      6     fn new(value: T) -> Self {
      7         Wrapper { value }
      8     }
      9 }
     10 
     11 fn main() {
     12     // You can optionally experiment here.
     13 }
     14 
     15 #[cfg(test)]
     16 mod tests {
     17     use super::*;
     18 
     19     #[test]
     20     fn store_u32_in_wrapper() {
     21         assert_eq!(Wrapper::new(42).value, 42);
     22     }
     23 
     24     #[test]
     25     fn store_str_in_wrapper() {
     26         assert_eq!(Wrapper::new("Foo").value, "Foo");
     27     }
     28 }