Skip to main content

SerializerExt

Trait SerializerExt 

Source
pub trait SerializerExt<T>
where Self: SpecByteLen<T = T::V> + SpecSerializer<SVal = T::V> + Consistency<Val = T::V>, T: DeepView + ?Sized,
{ // Provided methods exec fn serialize<'a>(&self, v: &T, obuf: &'a mut [u8]) where Self: Serializer<OutputSlice<'a>, T> { ... } fn serialize_with_vec(&self, v: &T, obuf: &mut Vec<u8>) where Self: Serializer<Vec<u8>, T> { ... } }
Expand description

Convenience entry points for the two standard output destinations.

Provided Methods§

Source

exec fn serialize<'a>(&self, v: &T, obuf: &'a mut [u8])
where Self: Serializer<OutputSlice<'a>, T>,

requires
self.exec_inv(),
self.consistent(v.deep_view()),
obuf@.len() == self.byte_len(v.deep_view()),
ensures
final(obuf)@ == self.spec_serialize(v.deep_view()),

Serializes into an exactly-sized caller-provided slice without allocating.

Source

exec fn serialize_with_vec(&self, v: &T, obuf: &mut Vec<u8>)
where Self: Serializer<Vec<u8>, T>,

requires
self.exec_inv(),
self.consistent(v.deep_view()),
ensures
final(obuf)@ == old(obuf)@ + self.spec_serialize(v.deep_view()),

Serializes by appending to a growable Vec (though the Vec can be preallocated with Prepare/ByteLen).

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.

Implementors§

Source§

impl<T: DeepView + ?Sized, S> SerializerExt<T> for S
where S: SpecByteLen<T = T::V> + SpecSerializer<SVal = T::V> + Consistency<Val = T::V>,