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

Minimal implementation of TryFromBytes #316

Closed
wants to merge 3 commits into from
Closed

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Sep 3, 2023

This PR is a more minimal version of #279. Most notably, it doesn't rely on field projection, which was a significant source of complexity. A future PR which adds support for deriving TryFromBytes will need to tackle field projection.

Makes progress on #5.

joshlf and others added 3 commits September 3, 2023 22:21
The standard library's `MaybeUninit` type does not currently support
wrapping unsized types. This commit introduces a polyfill with the same
behavior as `MaybeUninit` which does support wrapping unsized types.

In this commit, the only supported types are sized types and slice
types. Later (as part of #29), we will add the ability to derive the
`AsMaybeUninit` trait, which will extend support to custom DSTs.

Makes progress on #29
`MaybeValid<T>` is a `T` which might not be valid. It is similar to
`MaybeUninit<T>`, but it is slightly more strict: any byte in `T` which
is guaranteed to be initialized is also guaranteed to be initialized in
`MaybeValid<T>` (see the doc comment for a more precise definition).

`MaybeValid` is a building block of the `TryFromBytes` design outlined
in #5.

Makes progress on #5
`TryFromBytes` can be implemented for types which are not `FromZeroes`
or `FromBytes`; it supports performing a runtime check to determine
whether a given byte sequence contains a valid instance of `Self`.

This is the first step of #5. Future commits will add support for a
custom derive and for implementing `TryFromBytes` on unsized types.

TODO: Add tests

Makes progress on #5
@joshlf joshlf closed this Sep 3, 2023
@joshlf joshlf deleted the try-from-bytes-minimal branch September 3, 2023 23:03
@joshlf
Copy link
Member Author

joshlf commented Sep 3, 2023

This was accidentally closed when renaming a branch. It's replaced by #317.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant