我试图逐行处理来自命令行的输出,但是我坚持处理str::Lines
。
我试图为每一行获取所有单词并对其进行处理(与某种模式进行比较)
我的代码:
// output came properly from command
let mut lines = String::from_utf8_lossy(&output.stdout).to_string().lines();
for line in lines {
let vec: Vec<&str> = line.collect();
// Try to do something with a split...
编译器抱怨:
error[E0599]: no method named `collect` found for type `&str` in the current scope
--> src/main.rs:218:39
|
218 | let vec: Vec<&str> = line.collect();
| ^^^^^^^
|
= note: the method `collect` exists but the following trait bounds were not satisfied:
`&mut &str : std::iter::Iterator`
`&mut str : std::iter::Iterator`
我想我可能可以将行复制为字符串并尝试将其转换,但是,由于我是Rust的新手,所以想获得一些建议/帮助,以使我可以更顺畅地转行吗?
答案 0 :(得分:0)
好的,我想出了解决此问题的方法,该示例中有几处错误:
let s = String::from_utf8_lossy(&output.stdout).to_string();
for line in s.lines() {
let vec: Vec<&str> = line.split(' ').collect();
// Try to do something with a split...