mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-01-14 00:00:02 +03:00
updated task
This commit is contained in:
parent
01fa21f160
commit
bfe7974a5f
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue