I have a function that takes char_vec: &Vec<Chars>
as an argument. I know that the length of each Chars
may be different - I want to get the length of the longest one. I'm trying to do it with a following code:
let longest = char_vec.iter().map(|x| x.count()).max().unwrap_or(0);
Unfortunately this fails with the following error:
error[E0507]: cannot move out of `*x` which is behind a shared reference
--> C:\Rust\playground\src\lib.rs:62:43
|
62 | let longest = char_vec.iter().map(|x| x.count()).max().unwrap_or(0);
| ^ move occurs because `*x` has type `std::str::Chars<'_>`, which does not implement the `Copy` trait
I don't really understand how to execute the count()
method here. The Chars
struct seems to not implement a common traits?