Lokathor/bytemuck

Deriving Pod for arbitrary generic types

reinerp opened this issue · 1 comments

If we were willing to break backwards compatibility, it would be possible to support deriving Pod for arbitrary generic types.

The approach:

  • extend trait Pod to include const POST_MONOMORPHISM_CHECKS_PASS: bool;
  • the derive(Pod) instance puts its checks inside this POST_MONOMORPHISM_CHECKS_PASS constant. Since this is a trait member, it is allowed to reference the generic types.
  • (the backwards incompatible part) require that any function that uses T: Pod to do some form of safe transmute of T must first do assert!(POST_MONOMORPHISM_CHECKS_PASS);.

We might do this some day for version 2 (but that's far far in the future).