pub trait WireReadPart: Sized {
// Required method
fn read_wire_part<const L: usize, const E: bool>(
curs: &mut WireCursor<'_>,
) -> Result<Self, WireError>;
}
Expand description
Deserialization to an owned data type from a portion of the wire smaller than what the data type would normally consume.
A type that implements this trait guarantees that it can be constructed using a specified
number of bytes (greater than zero but less than the size of the type) from the provided
WireCursor
. If the bytes contained on the wire would lead to the construction of an
invalid instance of the object, an error will be returned instead of the object.
This trait is most useful for reading integer values from the wire that are represented in fewer bytes than the data type, such as reading in 3 bytes to form a u32 or 5 bytes to form a u64.
Types implementing this trait should additionally implement WireRead
for
the case where L
is equal to the size of the type.
Required Methods§
Sourcefn read_wire_part<const L: usize, const E: bool>(
curs: &mut WireCursor<'_>,
) -> Result<Self, WireError>
fn read_wire_part<const L: usize, const E: bool>( curs: &mut WireCursor<'_>, ) -> Result<Self, WireError>
Consumes exactly L
bytes (where 0 < L
< size_of(type)) from curs
and returns an owned
instance of the specified type, or returns a WireError
on failure.
The generic boolean E
designates the intended endianness of the data being read. If E
is set to
true
, then the data will be deserialized in big endian format; if false
, it will be deserialized
in little endian.
§Errors
WireError::InsufficientBytes
- not enough bytes remained on the cursor to construct the type.
WireError::InvalidData
- the bytes retrieved from curs
could not be used to construct a
valid instance of the type.
WireError::Internal
- an internal error occurred in the wire-rs
library
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.