Lokathor/bytemuck

`Pod` derive should work for generic types with `#[repr(C, packed)]`

zakarumych opened this issue · 4 comments

#[repr(packed)] guarantee that there's will be no padding between fields.

Yeah if all the generics are pod and it's packed then it should all add up fine.

Exactly. In my case I generate structure based on user-defined type. It may have generics and in general layout is out of my control. Generated structure must be Pod to support casting to/from bytes.
For this I add #[repr(C, packed)] attribute, but have to implement Pod trait manually which I'd like to avoid.

I've never really been familiar with how the derive code works, so this would have to be a PR submission from someone else.

AFAIK derive code generates call to transmute from bytes array with size equal to combined size of all fields to the structure (or vice versa), which fails compilation if sizes don't match. It also always fail for generic structures as it can't prove sizes match in all cases.
For packed representation derive macro should simply skip that step.