的本来我写了这个:借款变化的类型为向量
fn split_line(line: &String) -> Vec<String> {
let mut chars = line.chars();
let mut vec = Vec::new();
let mut s = String::from("");
while let Some(x) = chars.next() {
match x {
'<' => {},
'/' => {
vec.push(s);
break;
}
' ' => {
vec.push(s);
s.clear();
}
_ => s.push(x),
}
}
vec
}
,并收到此错误: use of moved value: 's'
所以我改变vec.push(s)
到vec.push(&s)
,这打消了我原来的错误,但改变VEC从std::vec::Vec<std::string::String>
到std::vec::Vec<&std::string::String>
。
为什么?我如何在不改变vec的情况下借钱?
Dosen't this make a vector of empty strings?只是改变数字? –