Trait rkyv::ser::Allocator

source ·
pub unsafe trait Allocator<E = <Self as Fallible>::Error> {
    // Required methods
    unsafe fn push_alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, E>;
    unsafe fn pop_alloc(
        &mut self,
        ptr: NonNull<u8>,
        layout: Layout,
    ) -> Result<(), E>;
}
Expand description

A serializer that can allocate scratch space.

§Safety

push_alloc must return a pointer to unaliased memory which fits the provided layout.

Required Methods§

source

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

Allocates scratch space of the requested size.

§Safety

layout must have non-zero size.

source

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

Deallocates previously allocated scratch space.

§Safety
  • The allocations pushed on top of the given allocation must not be popped after calling pop_alloc.
  • layout must be the same layout that was used to allocate the block of memory for the given pointer.

Implementations on Foreign Types§

source§

impl<T: Allocator<E>, E> Allocator<E> for Strategy<T, E>

source§

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

source§

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

Implementors§

source§

impl<E> Allocator<E> for ArenaHandle<'_>

Available on crate feature alloc only.
source§

impl<E> Allocator<E> for SubAllocator<'_>
where E: Source,

source§

impl<T: Allocator<E>, E> Allocator<E> for AllocationTracker<T>

source§

impl<W, A: Allocator<E>, S, E> Allocator<E> for Serializer<W, A, S>