Skip to main content

DeserializableSlice

Trait DeserializableSlice 

Source
pub trait DeserializableSlice<const N: usize>: Serializable<N> {
    // Provided methods
    fn from_slice(buf: &[u8]) -> Result<Self, Self::Error>
       where Self: Sized,
             Self::Error: BadLength { ... }
    fn from_reader<R>(buf: &mut R) -> Result<Self, Self::Error>
       where R: Read,
             Self: Sized,
             Self::Error: BadLength { ... }
}
Expand description

An optional trait used to implement DeserializableSlice::from_slice on top of types that use the Serializable trait. The default implementation makes use of Serializable trait to provide the necessary deserialization functionality without additional code from the consumer.

Provided Methods§

Source

fn from_slice(buf: &[u8]) -> Result<Self, Self::Error>
where Self: Sized, Self::Error: BadLength,

Deserialize a slice of u8 into Self

Source

fn from_reader<R>(buf: &mut R) -> Result<Self, Self::Error>
where R: Read, Self: Sized, Self::Error: BadLength,

Deserialize the type by reading exactly N bytes from a reader. Successful short reads are retried. If the reader makes no progress or returns an error before filling the buffer, a bad-length error is returned. The bytes read are removed from the reader, including bytes read before an error or end of input.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, const N: usize> DeserializableSlice<N> for T
where T: Serializable<N>,