Trait miden_core::utils::Deserializable
source · pub trait Deserializable: Sized {
// Required method
fn read_from<R>(source: &mut R) -> Result<Self, DeserializationError>
where R: ByteReader;
// Provided methods
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError> { ... }
fn read_batch_from<R>(
source: &mut R,
num_elements: usize
) -> Result<Vec<Self>, DeserializationError>
where R: ByteReader { ... }
}
Expand description
Defines how to deserialize Self
from bytes.
Required Methods§
sourcefn read_from<R>(source: &mut R) -> Result<Self, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<Self, DeserializationError>where R: ByteReader,
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
source
does not contain enough bytes to deserializeSelf
. - Bytes read from the
source
do not represent a valid value forSelf
.
Provided Methods§
sourcefn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Attempts to deserialize the provided bytes
into Self
and returns the result.
Errors
Returns an error if:
- The
bytes
do not contain enough information to deserializeSelf
. - The
bytes
do not represent a valid value forSelf
.
Note: if bytes
contains more data than needed to deserialize self
, no error is
returned.
sourcefn read_batch_from<R>(
source: &mut R,
num_elements: usize
) -> Result<Vec<Self>, DeserializationError>where
R: ByteReader,
fn read_batch_from<R>( source: &mut R, num_elements: usize ) -> Result<Vec<Self>, DeserializationError>where R: ByteReader,
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
source
does not contain enough bytes to deserialize the specified number of elements. - Bytes read from the
source
do not represent a valid value forSelf
for any of the elements.
Note: if the error occurs, the reader is not rolled back to the state prior to calling this function.
Object Safety§
This trait is not object safe.