以下两行:
let x = Box::new(("slefj".to_string(), "a".to_string()));
let (a, b) = *x;
Run Code Online (Sandbox Code Playgroud)
产生错误:
error[E0382]: use of moved value: `x`
--> src/main.rs:3:13
|
3 | let (a, b) = *x;
| - ^ value used here after move
| |
| value moved here
|
= note: move occurs because `x.0` has type `std::string::String`, which does not implement the `Copy` trait
Run Code Online (Sandbox Code Playgroud)
有趣的是,如果我使用包含多个部分的枚举类型执行此操作,我会得到一个稍微不同的错误:
enum Tree {
Nil,
Pair(Box<Tree>, Box<Tree>),
}
fn main() {
let x = Box::new(Tree::Nil);
match *x {
Tree::Pair(a, …Run Code Online (Sandbox Code Playgroud) rust ×1