-
Notifications
You must be signed in to change notification settings - Fork 127
Open
Description
The docs for TryFromBytes
say
Code should not generally assume that values produced by
IntoBytes
will necessarily be accepted as valid byTryFromBytes
.
It would be helpful to explain cases where these traits are asymmetrical, so that people could use TryFromBytes
with confidence. As written, it seems like even trivial code is of unknown correctness, e.g.
use zerocopy::{IntoBytes, TryFromBytes, Immutable, KnownLayout};
#[derive(Debug, PartialEq, TryFromBytes, IntoBytes, Immutable, KnownLayout)]
struct Foo {
hello: u32,
world: u32,
}
fn main() {
let f = Foo {
hello: 0x1234,
world: 0x5678,
};
let bytes = f.as_bytes();
let f_ = Foo::try_ref_from_bytes(bytes).expect("is this okay to do?");
assert_eq!(&f, f_);
}
Metadata
Metadata
Assignees
Labels
No labels