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

Add TryFromBytes::try_from_ref, impl for bool #647

Merged
merged 1 commit into from
Nov 28, 2023

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Nov 27, 2023

Add the TryFromBytes::try_from_ref method, which permits conditionally converting a &[u8] to a &Self, using is_bit_valid for runtime validation.

Implement TryFromBytes for bool.

Add a framework for testing TryFromBytes impls.

Makes progress on #5

@joshlf joshlf requested a review from jswrenn November 27, 2023 23:32
@joshlf joshlf force-pushed the try-from-bytes-external-impls-not-from-bytes branch from 9fcfb42 to 91b03f2 Compare November 27, 2023 23:39
Add the `TryFromBytes::try_from_ref` method, which permits conditionally
converting a `&[u8]` to a `&Self`, using `is_bit_valid` for runtime
validation.

Implement `TryFromBytes` for `bool`.

Add a framework for testing `TryFromBytes` impls.

Makes progress on #5
@joshlf joshlf force-pushed the try-from-bytes-external-impls-not-from-bytes branch from 91b03f2 to bf516d7 Compare November 28, 2023 00:36
where
Self: KnownLayout,
{
let maybe_self = Ptr::from(bytes).try_cast_into_no_leftover::<Self>()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still pondering how we might improve this name. What a mouthful! Maybe try_cast_all_into?

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh, it's an internal API. I'm not too worried about it being verbose, and IMO it's more important to be clear.

@joshlf joshlf added this pull request to the merge queue Nov 28, 2023
Merged via the queue into main with commit 7d8117f Nov 28, 2023
126 checks passed
@joshlf joshlf deleted the try-from-bytes-external-impls-not-from-bytes branch November 28, 2023 18:22
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