如何通过分割包含空格的字符串返回一个字符串向量?
fn line_to_words(line: &str) -> Vec<String> {
line.split_whitespace().collect()
}
fn main() {
println!( "{:?}", line_to_words( "string with spaces in between" ) );
}
以上代码返回以下错误
line.split_whitespace().collect()
| ^^^^^^^ value of type `std::vec::Vec<std::string::String>` cannot be built from `std::iter::Iterator<Item=&str>`
|
= help: the trait `std::iter::FromIterator<&str>` is not implemented for `std::vec::Vec<std::string::String>`