Trait winter_utils::Deserializable [−][src]
pub trait Deserializable: Sized { fn read_from<R: ByteReader>(
source: &mut R
) -> Result<Self, DeserializationError>; fn read_batch_from<R: ByteReader>(
source: &mut R,
num_elements: usize
) -> Result<Vec<Self>, DeserializationError> { ... } }
Expand description
Defines how to deserialize Self from bytes.
Required methods
fn read_from<R: ByteReader>(
source: &mut R
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>(
source: &mut R
) -> Result<Self, DeserializationError>
Reads a sequence of bytes from the provided source, attempts to deserialize these bytes
into Self, and returns the result.
Errors
Returns an error if:
- The
sourcedoes not contain enough bytes to deserializeSelf. - Bytes read from the
sourcedo not represent a valid value forSelf.
Provided methods
fn read_batch_from<R: ByteReader>(
source: &mut R,
num_elements: usize
) -> Result<Vec<Self>, DeserializationError>
fn read_batch_from<R: ByteReader>(
source: &mut R,
num_elements: usize
) -> Result<Vec<Self>, DeserializationError>
Reads a sequence of bytes from the provided source, attempts to deserialize these bytes
into a vector with the specified number of Self elements, and returns the result.
Errors
Returns an error if:
- The
sourcedoes not contain enough bytes to deserialize the specified number of elements. - Bytes read from the
sourcedo not represent a valid value forSelffor any of the elements.
Note: if the error occurs, the reader is not rolled back to the state prior calling this function.