Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProbablyPortable: A potential protector against platform peculiarities #1262

Open
jswrenn opened this issue May 14, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@jswrenn
Copy link
Collaborator

jswrenn commented May 14, 2024

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) or repr(transparent), whose members are ProbablyPortable
  • 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.

@jswrenn jswrenn added the enhancement New feature or request label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant