我有以下代码(你可以
try it on play.rust-lang.org
):
pub enum InnerStream {
Root,
Transaction {
v: Vec<u32>,
parent: Box<InnerStream>,
},
}
impl InnerStream {
pub fn rollback(self) -> InnerStream {
match self {
InnerStream::Transaction { v: _v, parent } => match *parent {
InnerStream::Root => InnerStream::Root,
InnerStream::Transaction {
v,
parent: parent_parent,
} => InnerStream::Transaction {
v,
parent: parent_parent,
},
},
InnerStream::Root { .. } => panic!("Cannot rollback root stream."),
}
}
}
fn main() {}
(这是一个例子,不是真的,如果看起来没用的话别担心)
在我看来很好,但借书检查程序给了我以下错误:
error[E0382]: use of collaterally moved value: `(parent as InnerStream::Transaction).parent`
--> src/main.rs:16:29
|
15 | v,
| - value moved here
16 | parent: parent_parent,
| ^^^^^^^^^^^^^ value used here after move
|
= note: move occurs because the value has type `std::vec::Vec<u32>`, which does not implement the `Copy` trait
这个错误的原因是什么?我该如何修复它?