์ด ์ฝ๋๋ ์ปดํ์ผ์ ์คํจํฉ๋๋ค.
struct Foo;
struct Bar {
a: Foo,
b: Foo,
}
fn main() {
let bar = Box::new(Bar { a: Foo, b: Foo });
let Bar { a, b } = *bar;
}
error[E0382]: use of moved value: `bar`
--> x.rs:11:18
|
11 | let Bar { a, b } = *bar;
| - ^ value used here after move
| |
| value moved here
|
= note: move occurs because `bar.a` has type `Foo`, which does not implement the `Copy` trait
๊ทธ๋ฌ๋ ์์ deref์ destructure ์ฌ์ด์ ์ค๊ฐ let ๋ฐ์ธ๋ฉ์ ์ฝ์ ํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๋ค.
fn main() {
let bar = Box::new(Bar { a: Foo, b: Foo });
let Bar { a, b } = { let intermediate = *bar; intermediate };
}
์ด๊ฒ์ ๋ฒ๊ทธ์ฒ๋ผ ๋๊ปด์ง๋๋ค.
์ํฅ์๋ฐ๋ ๋ฒ์ :
rustc 1.23.0 (766bd11c8 2018-01-01)
rustc 1.25.0-nightly (73ac5d6a8 2018-01-11)
์์ ํจํด์์๋ ๋ฐ์ํฉ๋๋ค.
#![feature(box_patterns)]
struct Foo;
struct Bar {
a: Foo,
b: Foo,
}
fn main() {
let bar = Box::new(Bar { a: Foo, b: Foo });
let box Bar { a, b } = bar;
}
์ด๊ฒ์ https://github.com/rust-lang/rust/issues/16223 ์ ์์์์ ๋๋ค
๋ถ๋ฅ :์ด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค!
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์์ ํจํด์์๋ ๋ฐ์ํฉ๋๋ค.