pub trait Deserializable: Sized {
// Required method
fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>;
// Provided method
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError> { ... }
}Expand description
Defines how to deserialize Self from bytes.
Required Methods§
Sourcefn 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§
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
bytesdo not contain enough information to deserializeSelf. - The
bytesdo not represent a valid value forSelf.
Note: if bytes contains more data than needed to deserialize self, no error is
returned.
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.