I'm trying to add a couple entries to a vec but I keep getting mismatching types:
pub fn create_lib_file(name: &str, targets: Vec<&str>) -> String {
let mut my_vec = vec![
"[lib]",
"",
"",
"[files]",
"",
"",
"[general]",
"",
];
// The targets are just strings passed from the CLI command.
for t in targets {
match t {
"one" => {
let file_name = format!("user/test/{}.dll", name);
let slice = &[file_name];
my_vec.splice(2..2, slice.iter().cloned());
}
}
}
return my_vec.join("\n");
}
This gives me an error:
error[E0271]: type mismatch resolving `<std::slice::Iter<'_, std::string::String> as std::iter::Iterator>::Item == &&str`
--> src/lib.rs:19:24
|
19 | my_vec.splice(2..2, slice.iter().cloned());
| ^^^^^^ expected struct `std::string::String`, found `&str`
|
= note: expected reference `&std::string::String`
found reference `&&str`
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::iter::Cloned<std::slice::Iter<'_, std::string::String>>`
I assume that this has to do with the file_name
so I tried using to_owned()
and to_string()
but nothing I've tried so far to convert the file_name
to String
has worked.