mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Complete generics exercises
This commit is contained in:
parent
38450a4493
commit
a6ab524725
|
@ -6,9 +6,19 @@
|
||||||
// Execute `rustlings hint generics1` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint generics1` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut shopping_list: Vec<?> = Vec::new();
|
let mut shopping_list: Vec<&str> = Vec::new();
|
||||||
shopping_list.push("milk");
|
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);
|
||||||
|
// }
|
|
@ -6,14 +6,12 @@
|
||||||
// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
struct Wrapper<T> {
|
||||||
|
value: T,
|
||||||
struct Wrapper {
|
|
||||||
value: u32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Wrapper {
|
impl<T> Wrapper<T> {
|
||||||
pub fn new(value: u32) -> Self {
|
pub fn new(value: T) -> Self {
|
||||||
Wrapper { value }
|
Wrapper { value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue