This code:
fn main() {
let input = String::from("The quick brown fox");
for s in input.split(" ") {
let s2: String = s;
println!("{:?}", s2)
}
}
gives me this error:
error[E0308]: mismatched types
--> src\main.rs:8:26
|
8 | let s2: String = s;
| ------ ^
| | |
| | expected struct `std::string::String`, found `&str`
| | help: try using a conversion method: `s.to_string()`
| expected due to this
Do I have to do what the compiler recommends (converting s
inside the loop) or can I change the loop so that I get String
s from the splitting directly?