我有一个 struct :
struct ThreeDPoint {
x: f32,
y: f32,
z: f32
}
在实例化之后,我想对三个属性中的extract two个进行分析:
let point: ThreeDPoint = ThreeDPoint { x: 0.3, y: 0.4, z: 0.5 };
let ThreeDPoint { x: my_x, y: my_y } = point;
编译器抛出以下错误:
error[E0027]: pattern does not mention field `z`
--> src/structures.rs:44:9
|
44 | let ThreeDPoint { x: my_x, y: my_y } = point;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `z`
在JavaScript(ES6)中,等效的解构如下所示:
let { x: my_x, y: my_y } = point;