Complete generics exercises

This commit is contained in:
Suzie Kim 2024-02-02 10:33:50 -05:00
parent 38450a4493
commit a6ab524725
No known key found for this signature in database
GPG key ID: 83C4CC3808F9AAE9
2 changed files with 16 additions and 8 deletions

View file

@ -6,9 +6,19 @@
// Execute `rustlings hint generics1` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
fn main() {
let mut shopping_list: Vec<?> = Vec::new();
let mut shopping_list: Vec<&str> = Vec::new();
shopping_list.push("milk");
}
// fn main() {
// let mut shopping_list: Vec<&str> = Vec::new();
// // shopping_list.push("milk");
// add_to_shopping_list(shopping_list, "milk")
// }
// fn add_to_shopping_list<T>(mut list: Vec<T>, grocery: T) {
// list.push(grocery);
// }

View file

@ -6,14 +6,12 @@
// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
struct Wrapper {
value: u32,
struct Wrapper<T> {
value: T,
}
impl Wrapper {
pub fn new(value: u32) -> Self {
impl<T> Wrapper<T> {
pub fn new(value: T) -> Self {
Wrapper { value }
}
}