pre-RFC FromBits/IntoBits

@jmst I’ll try to summarize your proposal as good as I can. You propose to add an auto trait:

auto trait Compatible<T> {
    fn from_compatible(T) -> Self; // needed for the explicit impls
}

that:

  • is automatically derived for all permutations of two equally-sized equally-aligned types with whose fields are all public,
  • allows coercing T as Self, e.g., using Self::from_compatible(T) (or some other syntax)
  • is transitive: allows coercing T as V, if Compatible<T> for U and Compatible<U> for V

For types with private fields, the users would need to specify this trait manually for the relations they care about and due to transitivity the compiler would “fill in the blanks” from the relations the users specifies to the relations the target types support.

Is that it?