`ProbablyPortable`: A potential protector against platform peculiarities
jswrenn opened this issue · 0 comments
I propose a safe, derivable ProbablyPortable
trait, which provides a (very good) best-effort analysis and marker of probable portability. If a type is ProbablyPortable
it probably:
- has consistent layout across compilations, platforms and toolchains
- does not have an endian-sensitive representation
We will provide base implementations of ProbablyPortable
for ()
, bool
, i8
, u8
, and zerocopy's endian-aware types. An implementation is also provided for arrays of ProbablyPortable
elements.
derive(ProbablyPortable)
can be applied to:
- structs and unions marked
repr(C)
orrepr(transparent)
, whose members areProbablyPortable
- enums with an explicit integer repr, whose members are
ProbablyPortable
The documentation of ProbablyPortable
will instruct users that it should not be derived on types whose APIs are endian aware in non-portable ways. However, it is not, strictly speaking, a violation of ProbablyPortable
's contract to do so — the proposed trait is called ProbablyPortable
, not Portable
, because a derive
cannot guarantee this.