我有一个 Vec<&str>
,我想从所有元素中移除一个前缀。这是我模糊的意图:
fn remove_prefix(v: &mut [&str], prefix: &str) {
for t in v.iter_mut() {
t = t.trim_left_matches(prefix);
}
}
然而,我似乎无法将所有的 mut
放在正确的位置。或者这是与生命周期相关的事情?有人可以给我一点提示吗?以下是当前的错误信息:
makefile_to_qbs.rs:22:7: 22:34 error: mismatched types:
expected `&mut &str`,
found `&str`
(values differ in mutability) [E0308]
makefile_to_qbs.rs:22 t = t.trim_left_matches(prefix);