pub trait FromBytes<'a> {
// Required method
fn from_bytes(bytes: &mut impl Iterator<Item = &'a [u8]>) -> Self;
}
Expand description
A type that can be reconstituted from byte slices with lifetime 'a
.
Implementors of this trait almost certainly reference the lifetime 'a
themselves,
unless they actively deserialize the bytes (vs sit on the slices, as if zero-copy).
Required Methods§
Sourcefn from_bytes(bytes: &mut impl Iterator<Item = &'a [u8]>) -> Self
fn from_bytes(bytes: &mut impl Iterator<Item = &'a [u8]>) -> Self
Reconstructs self
from a sequence of correctly aligned and sized bytes slices.
The implementation is expected to consume the right number of items from the iterator,
which may go on to be used by other implementations of FromBytes
.
The implementation should aim for only doing trivial work, as it backs calls like
borrow
for serialized containers.
Implementations should almost always be marked as #[inline(always)]
to ensure that
they are inlined. A single non-inlined function on a tree of from_bytes
calls
can cause the performance to drop significantly.
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.