【发布时间】:2021-02-13 03:48:27
【问题描述】:
请帮我解决以下错误:
error[E0382]: use of moved value: `nd3`
--> src/main.rs:21:21
|
19 | Node::Y { nd: nd3, max: max } => {
| --- move occurs because `nd3` has type `std::boxed::Box<Node>`, which does not implement the `Copy` trait
20 | for m in 0..max - 1 {
21 | match recur(nd3) {
| ^^^ value moved here, in previous iteration of loop
代码如下。请不要介意代码看起来毫无意义,因为我对其进行了简化:
enum Node {
X { x: usize },
Y { nd: Box<Node>, max: usize },
Z { Nd: Vec<Box<Node>> },
}
fn recur(nd: Box<Node>) -> Result<usize, ()> {
match *nd {
/// ...
Node::Y { nd: nd3, max: max } => {
for m in 0..max - 1 {
match recur(nd3) {
Ok(y) => return Ok(y),
_ => {}
}
}
return Ok(123);
}
_ => {}
}
return Ok(0);
}
【问题讨论】:
标签: rust borrow-checker ownership