rust-lang / rustlings

:crab: Small exercises to get you used to reading and writing Rust code!
https://rustlings.cool
MIT License
53.83k stars 10.13k forks source link

Feature/generics3 updt from old pr #2043

Open poneciak57 opened 3 months ago

poneciak57 commented 3 months ago

Created a new pull request based on the previous one (#1470).

Added a new generic exercise that focuses on function reusability using generics.

poneciak57 commented 3 months ago

One of the checks failed Rustlings Tests / dev-check (pull_request) It told me to run command cargo run -- dev update but this failed should i open an issue or should i just update this file manually ?

windows 11 rustup 1.27.1 cargo 1.79.0 Error message:

cargo run -- dev update
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.18s
     Running `target\debug\rustlings.exe dev update`
Error: Failed to update the file `dev/Cargo.toml`

Caused by:
    Failed to find the start of the `bin` list (`bin = [`)
error: process didn't exit successfully: `target\debug\rustlings.exe dev update` (exit code: 1)
mo8it commented 3 months ago

I can take care of the CI test later. Probably a Windows issue.

We shouldn't use traits / trait bounds because the exercises about them are after the generics exercises.

How about a function taking &[Option<T>] and returning Vec<T> containing only the Some values?

poneciak57 commented 3 months ago

I changed stringify to this:

fn into_dispose_nulls<T>(list: Vec<Option<T>>) -> Vec<T> {
    list.into_iter().flatten().collect()
}

i tried to have &[Option<T>] as an argument but it requires T to implement Clone (and i couldn't find any suitable workaround)

mo8it commented 3 months ago

i tried to have &[Option] as an argument but it requires T to implement Clone (and i couldn't find any suitable workaround)

Oh, yeah. We would need to return something like Vec<&T> otherwise. But this is fine how you did it with Vec as argument.