summaryrefslogtreecommitdiff
path: root/rustlings/exercises
diff options
context:
space:
mode:
Diffstat (limited to 'rustlings/exercises')
-rw-r--r--rustlings/exercises/14_generics/generics1.rs2
-rw-r--r--rustlings/exercises/14_generics/generics2.rs8
2 files changed, 5 insertions, 5 deletions
diff --git a/rustlings/exercises/14_generics/generics1.rs b/rustlings/exercises/14_generics/generics1.rs
index 87ed990..7e5571f 100644
--- a/rustlings/exercises/14_generics/generics1.rs
+++ b/rustlings/exercises/14_generics/generics1.rs
@@ -6,7 +6,7 @@ fn main() {
// TODO: Fix the compiler error by annotating the type of the vector
// `Vec<T>`. Choose `T` as some integer type that can be created from
// `u8` and `i8`.
- let mut numbers = Vec::new();
+ let mut numbers: Vec<i32> = Vec::new();
// Don't change the lines below.
let n1: u8 = 42;
diff --git a/rustlings/exercises/14_generics/generics2.rs b/rustlings/exercises/14_generics/generics2.rs
index 8908725..ba77625 100644
--- a/rustlings/exercises/14_generics/generics2.rs
+++ b/rustlings/exercises/14_generics/generics2.rs
@@ -1,12 +1,12 @@
// 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 {
- value: u32,
+struct Wrapper<T> {
+ value: T,
}
// TODO: Adapt the struct's implementation to be generic over the wrapped value.
-impl Wrapper {
- fn new(value: u32) -> Self {
+impl<T> Wrapper<T> {
+ fn new(value: T) -> Self {
Wrapper { value }
}
}