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 Strings from the splitting directly?
fn main()to make it a MWE? I will do that next time, my apologies.Iteratorimplementation it always yields&str, it is better if you specify why you need this done internally ?inis some kind of pattern I'm not really clear yet on what is possible there.