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 #317

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 joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 2019700 to 038ccb3 Compare September 4, 2023 00:23
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch 3 times, most recently from 3802900 to 665ab99 Compare September 4, 2023 17:28
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 038ccb3 to d0ff76b Compare September 4, 2023 19:25
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from 665ab99 to ce8b5e8 Compare September 4, 2023 19:25
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from d0ff76b to 8ed6a15 Compare September 4, 2023 19:37
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from ce8b5e8 to 0d31add Compare September 4, 2023 19:37
@joshlf joshlf requested a review from jswrenn September 4, 2023 19:52
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 8ed6a15 to b6457af Compare September 4, 2023 21:52
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from 0d31add to 52e942f Compare September 4, 2023 21:52
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@joshlf joshlf mentioned this pull request Aug 5, 2023
3 tasks
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch 2 times, most recently from d38f809 to 78aefe2 Compare September 5, 2023 16:45
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from b6457af to 98afbb5 Compare September 5, 2023 17:51
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from 78aefe2 to 56596ac Compare September 5, 2023 17:51
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 98afbb5 to 17a8cff Compare September 5, 2023 18:04
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from 56596ac to 041ef79 Compare September 5, 2023 18:04
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 17a8cff to 739d047 Compare September 5, 2023 18:57
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from 041ef79 to fd5327f Compare September 5, 2023 18:57
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 739d047 to 9bc7911 Compare September 5, 2023 20:03
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from fd5327f to 9c4a7a4 Compare September 5, 2023 20:03
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 9bc7911 to 4b14ee1 Compare September 6, 2023 01:28
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from 9c4a7a4 to 51ce251 Compare September 6, 2023 01:28
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 4b14ee1 to d32107e Compare September 6, 2023 03:25
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from 51ce251 to 05003ee Compare September 6, 2023 03:25
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from d32107e to 01345db Compare September 6, 2023 03:50
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from 05003ee to 7aff258 Compare September 6, 2023 03:50
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 01345db to 66c0c30 Compare September 6, 2023 18:30
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from 7aff258 to c46c812 Compare September 6, 2023 18:30
@joshlf joshlf force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 66c0c30 to 3115668 Compare September 6, 2023 18:34
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from c46c812 to f886e19 Compare September 6, 2023 18:34
`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 force-pushed the try-from-bytes-minimal-2-maybe-valid branch from 3115668 to f5fc5ba Compare September 6, 2023 18:59
@joshlf joshlf force-pushed the try-from-bytes-minimal-3-try-from-bytes branch from f886e19 to 6e16ad3 Compare September 6, 2023 18:59
/// implementation of `TryFromBytes::is_bit_valid`.
///
/// [1] https://doc.rust-lang.org/std/primitive.char.html#method.from_u32
unsafe_impl!(char: TryFromBytes; |bytes: &[u8; 4]| {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-lang/reference#1401 has landed; use u32 as a representation instead.

@joshlf
Copy link
Member Author

joshlf commented Nov 27, 2023

Superseded by #353

@joshlf joshlf closed this Nov 27, 2023
@joshlf joshlf deleted the try-from-bytes-minimal-3-try-from-bytes branch November 27, 2023 18:51
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.

2 participants