ByteValued is an unsafe trait and implementing it is tricky with the padding requirement. But I think it can be autoderived.
Basically, a custom derive that does two things:
- Emits something like
const __ASSERT_SIZES_Foo: [(); mem::size_of::<Foo>()] = [(); mem::size_of::<Field1>() + mem::size_of::<Field2>() + ...] ] ] to assert that there is no padding
- Emit some test function that ends up asserting bounds on all subfields.
This might significantly reduce the amount of unsafe needed by crate users.