Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated generics1 #1470

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions exercises/generics/generics1.rs
@@ -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 last_on_list(list: &[&str]) -> &str {
list.last().unwrap()
}

// Do not change the main method
fn main() {
let mut shopping_list: Vec<?> = Vec::new();
shopping_list.push("milk");
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));
}
7 changes: 5 additions & 2 deletions info.toml
Expand Up @@ -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"
Expand Down