我有一个结构体:
struct ThreeDPoint {
x: f32,
y: f32,
z: f32
}
我想在实例化后提取其中的两个属性:
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;