mirror of
https://github.com/ArthurDanjou/rustlings.git
synced 2026-02-04 05:37:50 +01:00
- Created empty solution files for various exercises in strings, modules, hashmaps, options, error handling, generics, traits, lifetimes, tests, iterators, smart pointers, threads, macros, clippy, conversions, and quizzes. - Each solution file contains a main function with a comment indicating that it will be automatically filled after completing the exercise. - Added a README.md file to provide information about the solutions and their purpose.
32 lines
668 B
Rust
32 lines
668 B
Rust
// This powerful wrapper provides the ability to store a positive integer value.
|
|
// TODO: Rewrite it using a generic so that it supports wrapping ANY type.
|
|
struct Wrapper<T> {
|
|
value: T,
|
|
}
|
|
|
|
// TODO: Adapt the struct's implementation to be generic over the wrapped value.
|
|
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");
|
|
}
|
|
}
|