我想获得向量元素的所有组合。我正在使用 itertools 的组合()函数。很好,但现在我想操纵向量的元素。因此我需要一个迭代器来生成向量元素的可变引用......
我的代码基本上如下所示:
let mut v: Vec<MyType> = vec![];
for vpair in v.iter_mut().combinations(2) {
vpair.first().unwrap().do_something(vpair.last().unwrap());
}
Run Code Online (Sandbox Code Playgroud)
通过调用我想在每次迭代中do_something()操作vpair.first().unwrap()and 。vpair.last().unwrap()
我收到的错误是:
the trait std::clone::Clone is not implemented for &mut MyType
我能以某种方式解决这个问题还是我完全走错了路?
rust ×1