Trait epserde::deser::Deserialize

source ·
pub trait Deserialize: TypeHash + ReprHash + DeserializeInner {
    // Required methods
    fn deserialize_full(backend: &mut impl ReadNoStd) -> Result<Self>;
    fn deserialize_eps(backend: &[u8]) -> Result<Self::DeserType<'_>>;

    // Provided methods
    fn load_full(path: impl AsRef<Path>) -> Result<Self> { ... }
    fn load_mem<'a>(
        path: impl AsRef<Path>
    ) -> Result<MemCase<<Self as DeserializeInner>::DeserType<'a>>> { ... }
    fn load_mmap<'a>(
        path: impl AsRef<Path>,
        flags: Flags
    ) -> Result<MemCase<<Self as DeserializeInner>::DeserType<'a>>> { ... }
    fn mmap<'a>(
        path: impl AsRef<Path>,
        flags: Flags
    ) -> Result<MemCase<<Self as DeserializeInner>::DeserType<'a>>> { ... }
}
Expand description

Main deserialization trait. It is separated from DeserializeInner to avoid that the user modify its behavior, and hide internal serialization methods.

It provides several convenience methods to load or map into memory structures that have been previously serialized. See, for example, Deserialize::load_full, Deserialize::load_mem, and Deserialize::mmap.

Required Methods§

source

fn deserialize_full(backend: &mut impl ReadNoStd) -> Result<Self>

Fully deserialize a structure of this type from the given backend.

source

fn deserialize_eps(backend: &[u8]) -> Result<Self::DeserType<'_>>

ε-copy deserialize a structure of this type from the given backend.

Provided Methods§

source

fn load_full(path: impl AsRef<Path>) -> Result<Self>

Commodity method to fully deserialize from a file.

source

fn load_mem<'a>( path: impl AsRef<Path> ) -> Result<MemCase<<Self as DeserializeInner>::DeserType<'a>>>

Load a file into heap-allocated memory and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory. Excess bytes are zeroed out.

The allocated memory will have MemoryAlignment as alignment: types with a higher alignment requirement will cause an alignment error.

source

fn load_mmap<'a>( path: impl AsRef<Path>, flags: Flags ) -> Result<MemCase<<Self as DeserializeInner>::DeserType<'a>>>

Load a file into mmap()-allocated memory and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory. Excess bytes are zeroed out.

The behavior of mmap() can be modified by passing some Flags; otherwise, just pass Flags::empty().

source

fn mmap<'a>( path: impl AsRef<Path>, flags: Flags ) -> Result<MemCase<<Self as DeserializeInner>::DeserType<'a>>>

Memory map a file and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory mapping.

The behavior of mmap() can be modified by passing some Flags; otherwise, just pass Flags::empty().

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: TypeHash + ReprHash + DeserializeInner> Deserialize for T

Blanket implementation that prevents the user from overwriting the methods in Deserialize.

This implementation checks the header written by the blanket implementation of crate::ser::Serialize and then delegates to DeserializeInner::_deserialize_full_inner or DeserializeInner::_deserialize_eps_inner.