pub unsafe trait FromBytes {
const MIN_LAYOUT: Layout;
// Provided methods
fn from_bytes(bytes: &[u8]) -> &Self { ... }
fn from_boxed(boxed: Box<[u8]>) -> Box<Self> { ... }
}
Expand description
Marker trait for types that can be safely converted to bytes.
Required Associated Constants§
Sourceconst MIN_LAYOUT: Layout
const MIN_LAYOUT: Layout
Specified the minimum layout requirements for the allocation:
- is at least as big as
MIN_LAYOUT.size()
- referenced/pointed data is at least as aligned as
MIN_LAYOUT.align()
For DSTs, final size should be exactly the same as the allocation’s.
§Safety
In Rust, it is considered UB for pointers/references/Box<T>
es to
be dangling, unaligned or pointing to invalid value.
The alignment check is done using MIN_LAYOUT
and thus can cause UB if
implemented incorrectly.
Provided Methods§
fn from_bytes(bytes: &[u8]) -> &Self
fn from_boxed(boxed: Box<[u8]>) -> Box<Self>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.