mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 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
|
||||
// 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);
|
||||
// }
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue