diff options
| author | mo8it <mo8it@proton.me> | 2024-06-27 02:25:11 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-06-27 02:25:11 +0200 |
| commit | de3f846a53055bbca5ec9dd6d536a31c82d39648 (patch) | |
| tree | c5ca723d1833700881b27dee0b397ccbb59167ee /solutions/14_generics | |
| parent | 46121b71cf2f4da296e80fad025eaee03c67dcd5 (diff) | |
generics2 solution
Diffstat (limited to 'solutions/14_generics')
| -rw-r--r-- | solutions/14_generics/generics2.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/solutions/14_generics/generics2.rs b/solutions/14_generics/generics2.rs index 4e18198..14f3f7a 100644 --- a/solutions/14_generics/generics2.rs +++ b/solutions/14_generics/generics2.rs @@ -1 +1,28 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +struct Wrapper<T> { + value: T, +} + +impl<T> Wrapper<T> { + fn new(value: T) -> Self { + Wrapper { value } + } +} + +fn main() { + // You can optionally experiment here. +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn store_u32_in_wrapper() { + assert_eq!(Wrapper::new(42).value, 42); + } + + #[test] + fn store_str_in_wrapper() { + assert_eq!(Wrapper::new("Foo").value, "Foo"); + } +} |
