pub trait DynSerializer {
    // Required methods
    fn pos_dyn(&self) -> usize;
    fn write_dyn(&mut self, bytes: &[u8]) -> Result<(), DynError>;
    unsafe fn push_scratch_dyn(
        &mut self,
        layout: Layout
    ) -> Result<NonNull<[u8]>, DynError>;
    unsafe fn pop_scratch_dyn(
        &mut self,
        ptr: NonNull<u8>,
        layout: Layout
    ) -> Result<(), DynError>;
}
Expand description

An object-safe version of Serializer.

Instead of an associated error type, DynSerializer returns the DynError type. If you have a serializer that already implements Serializer, then it will automatically implement DynSerializer.

Required Methods§

source

fn pos_dyn(&self) -> usize

Returns the current position of the serializer.

source

fn write_dyn(&mut self, bytes: &[u8]) -> Result<(), DynError>

Attempts to write the given bytes to the serializer.

source

unsafe fn push_scratch_dyn( &mut self, layout: Layout ) -> Result<NonNull<[u8]>, DynError>

Allocates scratch space of the requested size.

§Safety

layout must have non-zero size.

source

unsafe fn pop_scratch_dyn( &mut self, ptr: NonNull<u8>, layout: Layout ) -> Result<(), DynError>

Deallocates previously allocated scratch space.

§Safety
  • ptr must be the scratch memory last allocated with push_scratch.
  • layout must be the same layout that was used to allocate that block of memory.

Trait Implementations§

source§

impl<'a> Fallible for dyn DynSerializer + 'a

§

type Error = Box<dyn Any>

The error produced by any failing methods.
source§

impl<'a> ScratchSpace for dyn DynSerializer + 'a

source§

unsafe fn push_scratch( &mut self, layout: Layout ) -> Result<NonNull<[u8]>, Self::Error>

Allocates scratch space of the requested size. Read more
source§

unsafe fn pop_scratch( &mut self, ptr: NonNull<u8>, layout: Layout ) -> Result<(), Self::Error>

Deallocates previously allocated scratch space. Read more
source§

impl<'a> Serializer for dyn DynSerializer + 'a

source§

fn pos(&self) -> usize

Returns the current position of the serializer.
source§

fn write(&mut self, bytes: &[u8]) -> Result<(), Self::Error>

Attempts to write the given bytes to the serializer.
source§

fn pad(&mut self, padding: usize) -> Result<(), Self::Error>

Advances the given number of bytes as padding.
source§

fn align(&mut self, align: usize) -> Result<usize, Self::Error>

Aligns the position of the serializer to the given alignment.
source§

fn align_for<T>(&mut self) -> Result<usize, Self::Error>

Aligns the position of the serializer to be suitable to write the given type.
source§

unsafe fn resolve_aligned<T>( &mut self, value: &T, resolver: <T as Archive>::Resolver ) -> Result<usize, Self::Error>
where T: Archive + ?Sized,

Resolves the given value with its resolver and writes the archived type. Read more
source§

fn serialize_value<T>(&mut self, value: &T) -> Result<usize, Self::Error>
where T: Serialize<Self>,

Archives the given object and returns the position it was archived at.
source§

unsafe fn resolve_unsized_aligned<T>( &mut self, value: &T, to: usize, metadata_resolver: <T as ArchiveUnsized>::MetadataResolver ) -> Result<usize, Self::Error>
where T: ArchiveUnsized + ?Sized,

Resolves the given reference with its resolver and writes the archived reference. Read more
source§

fn serialize_unsized_value<T>( &mut self, value: &T ) -> Result<usize, Self::Error>
where T: SerializeUnsized<Self> + ?Sized,

Archives a reference to the given object and returns the position it was archived at.

Implementations on Foreign Types§

source§

impl<S: ScratchSpace + Serializer + ?Sized> DynSerializer for &mut S

source§

fn pos_dyn(&self) -> usize

source§

fn write_dyn(&mut self, bytes: &[u8]) -> Result<(), DynError>

source§

unsafe fn push_scratch_dyn( &mut self, layout: Layout ) -> Result<NonNull<[u8]>, DynError>

source§

unsafe fn pop_scratch_dyn( &mut self, ptr: NonNull<u8>, layout: Layout ) -> Result<(), DynError>

Implementors§