Closed
Description
Example I came up with (tried to reduce from a larger set of code I found this in)
fn main() {
let mut v = vec!["hello", "this", "is", "a", "test"];
let v2 = Vec::new();
v.into_iter().map(|s|s.to_owned()).collect::<Vec<_>>();
let mut a = String::new();
for i in v {
a = *i.to_string();
v2.push(a);
}
}
This gives a rather confusing error message:
error[E0308]: mismatched types
--> src/main.rs:10:7
|
10 | a = *i.to_string();
| ^^^^^^^^^^^^^^
| |
| expected struct `std::string::String`, found str
| help: try using a conversion method: `*i.to_string().to_string()`
|
= note: expected type `std::string::String`
found type `str`
meta:
rustc 1.30.0-nightly (d5a448b3f 2018-08-13)
binary: rustc
commit-hash: d5a448b3f47b22c9cb010198bdcc49d4392b090b
commit-date: 2018-08-13
host: x86_64-unknown-linux-gnu
release: 1.30.0-nightly
LLVM version: 7.0