-
Notifications
You must be signed in to change notification settings - Fork 104
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 trait #353
Add TryFromBytes trait #353
Conversation
b91a49a
to
c2b946e
Compare
547c468
to
f72320b
Compare
c2b946e
to
7dec672
Compare
320bc2c
to
879638f
Compare
f72320b
to
da9e996
Compare
da9e996
to
d8b1ce6
Compare
879638f
to
002bb4a
Compare
d8b1ce6
to
87cd2a8
Compare
002bb4a
to
d43fadf
Compare
87cd2a8
to
7adbc94
Compare
d43fadf
to
26f08fd
Compare
7adbc94
to
af95760
Compare
26f08fd
to
074c632
Compare
af95760
to
9742ace
Compare
074c632
to
5181ae1
Compare
9742ace
to
ed49647
Compare
5181ae1
to
f30994d
Compare
ed49647
to
90bee71
Compare
4a6a127
to
df988fb
Compare
90bee71
to
0ba3552
Compare
6c7af14
to
d7c16fa
Compare
68ab76d
to
a3235fc
Compare
80c12cf
to
2c9e7f1
Compare
a3235fc
to
2d0bef3
Compare
2c9e7f1
to
bbf9603
Compare
9c77d7e
to
f2e9656
Compare
//! - [`TryFromBytes`] supports non-`FromBytes` types by providing the ability | ||
//! to check the validity of a conversion at runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love this wording. @jswrenn any suggestions?
f2e9656
to
1244aba
Compare
/// # Panics | ||
/// | ||
/// `is_bit_valid` may panic. Callers are responsible for ensuring that any | ||
/// `unsafe` code remains sound even in the face of `is_bit_valid` | ||
/// panicking. (We support user-defined validation routines; so long as | ||
/// these routines are not required to be `unsafe`, there is no way to | ||
/// ensure that these do not generate panics.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @jswrenn @djkoloski Calling this out; I've updated all the safety comments in this PR to address panics.
c79a650
to
778533a
Compare
baa448f
to
73961ac
Compare
73961ac
to
df96950
Compare
/// TODO(https://github.com/rust-lang/reference/pull/1401): Use `&u32` | ||
/// instead once it's guaranteed that `align_of::<u32>() == | ||
/// align_of::<char>()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has landed; update this PR.
b69386f
to
806a8d7
Compare
`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: - More thorough tests for non-FromBytes types (bool, char, etc) - Tests that go through the `TryFromBytes` public methods rather than testing `is_bit_valid` directly - Update safety requirements for `is_bit_valid` now that it takes a `Ptr` rather than a `NonNull` - Update SAFETY comments in various places Makes progress on #5
806a8d7
to
e54c8d6
Compare
TryFromBytes
can be implemented for types which are notFromZeroes
orFromBytes
; it supports performing a runtime check to determine whether a given byte sequence contains a valid instance ofSelf
.This is the first step of #5. Future commits will add support for a custom derive and for implementing
TryFromBytes
on unsized types.Makes progress on #5