我正在建立一个锁链的未来
ActorFuture<Item = Vec<String>, Error = Vec<String>, Actor = Self>
成功后,它将具有与链接的所有期货的字符串输出向量.and_then
。第一次错误处理将停止,我想返回成功的期货输出和最终(失败的)未来错误。我想使用相同的向量来处理两条路径:ok 和 err。但是编译器抱怨:
242 | .map(|o| {v.push(o); v})
| --- value moved (into closure) here
243 | .map_err(|e| {v.push(format!("{}", e)); v})
| ^ value captured here after move
这是为什么?map
可以同时进去map_err
吗?在我的理解中,这绝不应该发生。
一个例子:
#[test]
fn test_map_and_map_err() {
let mut v = Vec::new();
Ok("foo".to_string())
.map(|i| { v.push(i); v })
.map_err(|e: String| { v.push(e); v });
}
error[E0382]: capture of moved value: `v`
--> src/lib.rs:6:32
|
5 | .map(|i| { v.push(i); v })
| --- value moved (into closure) here
6 | .map_err(|e: String| { v.push(e); v });
| ^ value captured here after move
|
= note: move occurs because `v` has type `std::vec::Vec<std::string::String>`, which does not implement the `Copy` trait