updated task

This commit is contained in:
Kacper Poneta 2023-04-05 22:10:13 +02:00
parent 01fa21f160
commit bfe7974a5f
2 changed files with 18 additions and 7 deletions

View file

@ -1,11 +1,19 @@
// This shopping list program isn't compiling!
// Use your knowledge of generics to fix it.
// generics1.rs
// Use your knowledge of generics to fix the function signature.
// 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();
shopping_list.push("milk");
fn last_on_list(list: &[&str]) -> &str {
list.last().unwrap()
}
// Do not change the main method
fn main() {
let names_list = vec!["maria", "jacob", "kacper"];
println!("last name on the list is: {}", last_on_list(&names_list));
let numbers_list = vec![1, 2, 3];
println!("last number on the list is: {}", last_on_list(&numbers_list));
}

View file

@ -667,8 +667,11 @@ name = "generics1"
path = "exercises/generics/generics1.rs"
mode = "compile"
hint = """
Vectors in Rust make use of generics to create dynamically sized arrays of any type.
You need to tell the compiler what type we are pushing onto this vector."""
Vectors in Rust use generics to create dynamically-sized arrays of any type.
The last_on_list function takes a vector as an argument, but only accepts vectors that store the &str type.
To allow the function to accept vectors that store any type, you can leverage your knowledge about generics.
If you're unsure how to proceed, please refer to the Rust Book at:
https://doc.rust-lang.org/book/ch10-01-syntax.html#in-function-definitions."""
[[exercises]]
name = "generics2"