Skip to main content

Allocator

Trait 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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

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<'_>

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>