Trait workflow_serializer::serializer::Serializer

source ·
pub trait Serializer: Sized {
    // Required methods
    fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>;
    fn deserialize<R: Read>(reader: &mut R) -> Result<Self>;

    // Provided methods
    fn try_from_slice(slice: &[u8]) -> Result<Self> { ... }
    fn try_to_vec(&self) -> Result<Vec<u8>> { ... }
}
Expand description

Serializer is a trait that allows for data serialization and deserialization similar to Borsh, but via a separate trait. This allows for serialization of additional metadata while using underlying Borsh primitives. For example: a struct can implement both Borsh and Serializer traits where Serializer can store custom metadata (e.g. struct version) and then store the struct using Borsh. Both Serializer and Borsh are almost identical, where Serializer is meant to signal intent for custom serialization. Serializer is a complimentary trait for Serializable struct and can be used to prevent direct Borsh serialization of a struct.

Required Methods§

source

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

Provided Methods§

source

fn try_from_slice(slice: &[u8]) -> Result<Self>

source

fn try_to_vec(&self) -> Result<Vec<u8>>

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<K, V> Serializer for BTreeMap<K, V>
where K: Serializer + Ord, V: Serializer,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

source§

impl<K, V> Serializer for HashMap<K, V>
where K: Serializer + Hash + Eq, V: Serializer,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

source§

impl<K, V> Serializer for AHashMap<K, V>
where K: Serializer + Send + Sync + Hash + Eq, V: Serializer + Send + Sync,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

source§

impl<T> Serializer for Option<T>
where T: Serializer + 'static,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

source§

impl<T> Serializer for BTreeSet<T>
where T: Serializer + Ord,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

source§

impl<T> Serializer for HashSet<T>
where T: Serializer + Send + Sync + Hash + Eq,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

source§

impl<T> Serializer for AHashSet<T>
where T: Serializer + Hash + Eq,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

source§

impl<T, E> Serializer for Result<T, E>
where T: Serializer + 'static, E: Display + BorshSerialize + BorshDeserialize + 'static,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

source§

impl<V> Serializer for Vec<V>
where V: Serializer,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self>

Implementors§