rust - Is there a way to destructure a struct partially? -


i have struct:

struct threedpoint {     x: f32,     y: f32,     z: f32 } 

and want extract two of 3 properties after instantiating it:

let point: threedpoint = threedpoint { x: 0.3, y: 0.4, z: 0.5 }; let threedpoint { x: my_x, y: my_y } = point; 

the compiler throws following error:

error[e0027]: pattern not mention field `z`   --> src/structures.rs:44:9    | 44 |     let threedpoint { x: my_x, y: my_y } = point;    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `z` 

in javascript (es6), equivalent destructuring this:

let { x: my_x, y: my_y } = point; 

.. field in struct or tuple pattern means "and rest":

let threedpoint { x: my_x, y: my_y, .. } = point; 

there's more in the rust book.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -