pub unsafe trait FromByteArray: ToByteArray {
// Required method
fn from_bytes(bytes: Self::Bytes) -> Self;
// Provided method
fn cast_bytes<Dst>(self) -> Dst
where Dst: FromByteArray<Bytes = Self::Bytes> { ... }
}Expand description
Types which can be transmuted from a byte array.
These are types for which any bit pattern is valid.
§Safety
This type must only be implemented for types for which any bit pattern is valid.
Required Methods§
Sourcefn from_bytes(bytes: Self::Bytes) -> Self
fn from_bytes(bytes: Self::Bytes) -> Self
Convert an array of bytes, in native order, into this type.
This is the same as from_ne_bytes for primitive types.
Provided Methods§
Sourcefn cast_bytes<Dst>(self) -> Dstwhere
Dst: FromByteArray<Bytes = Self::Bytes>,
fn cast_bytes<Dst>(self) -> Dstwhere
Dst: FromByteArray<Bytes = Self::Bytes>,
Convert this type to another of the same size.
This should compile to a zero-cost transmute.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".