Destructuring private fields

I have a Struct which has both pub fields and private fields. Can rust only destructuring the pub fields and ignore the private ones?

MyStruct {
pub x: f32,
y: f32,
pub z: f32

let foo = MyStruct { x: 0.3, y: 0.4, z: 0.5 };
let MyStruct { my_x, .., my_z } = foo;

I had to make some changes to get things to compile, but yes, it can.

1 Like

Thanks a lot, it works.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.