-
I'm interested in this for a specific scenario I'm working on - reinterpreting a byte buffer into a mutably referenced struct that may contain padding. Specifically, I'm trying to make (and automatically generate) more ergonomic bindings for WGSL uniform buffers, where the layout has certain alignment requirements and so they often have padding. Traditionally, I've done this just with My guess, after thinking about it for some time: if I try to do |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This specific pattern, of going from all initialized to a view where not all are initialized, has a slight hiccup. If it's an immutable view that's no problem, you're only looking, so it's okay to not look at some of the bytes. The mutable case is basically as you guessed: If it's a mutable view than a write will actually deinitialize some bytes, and then when you "undo" the |
Beta Was this translation helpful? Give feedback.
This specific pattern, of going from all initialized to a view where not all are initialized, has a slight hiccup. If it's an immutable view that's no problem, you're only looking, so it's okay to not look at some of the bytes.
The mutable case is basically as you guessed: If it's a mutable view than a write will actually deinitialize some bytes, and then when you "undo" the
&mut HasPadding
to have just&mut [u8]
again, there's some uninit memory in your byte slice.