I am trying to create a vector of strings using vec!, but it appears vec! converts it into a slice.
This is the code
impl ShowErr {
pub fn new<T> (args: &mut T) -> Result<ShowErr, String>
where
T: Iterator<Item = String>,
(some code deleted)
fn empty_args() {
let mut args: Vec<String> = vec![String::from("arg1"); 1];
assert_eq!(Err(String::from("Not enough arguments")),
ShowErr::new(&mut args.iter_mut()));
}
And I get the error
error[E0271]: type mismatch resolving `<std::slice::IterMut<'_, String> as Iterator>::Item == String`
--> src/lib.rs:31:6
|
9 | pub fn new<T> (args: &mut T) -> Result<ShowErr, String>
| --- required by a bound in this
10 | where
11 | T: Iterator<Item = String>,
| ------------- required by this bound in `ShowErr::new`
...
31 | ShowErr::new(&mut args.iter_mut()));
| ^^^^^^^^^^^^ expected struct `String`, found `&mut _`
|
= note: expected struct `String`
found mutable reference `&mut String`
Since args is a Vec of Strings, I'd expect to be able to produce an iterator from it that would return String, but that does not seem to be what is going on here