[][src]Trait alloc_compose::CallbackRef

pub unsafe trait CallbackRef {
    fn alloc(
        &self,
        layout: Layout,
        init: AllocInit,
        result: Result<MemoryBlock, AllocErr>
    );
fn dealloc(&self, ptr: NonNull<u8>, layout: Layout);
fn grow(
        &self,
        ptr: NonNull<u8>,
        layout: Layout,
        new_size: usize,
        placement: ReallocPlacement,
        init: AllocInit,
        result: Result<MemoryBlock, AllocErr>
    );
fn shrink(
        &self,
        ptr: NonNull<u8>,
        layout: Layout,
        new_size: usize,
        placement: ReallocPlacement,
        result: Result<MemoryBlock, AllocErr>
    );
fn owns(&self, success: bool); fn by_ref(&self) -> &Self { ... } }

Backend for the Proxy allocator.

As Callback is used in Proxy and AllocRef requires, that a cloned allocator must behave like the same allocator, Clone must not be implemented on types, which don't have a shared state. It's possible to use a reference by calling by_ref or to wrapping them into Rc or Arc in order to make them cloneable instead. Note, that Box, Rc, and Arc requires the "alloc"-feature to be enabled.

Safety

  • Clone must not be implemented on types, which don't have a shared state.

Required methods

fn alloc(
    &self,
    layout: Layout,
    init: AllocInit,
    result: Result<MemoryBlock, AllocErr>
)

Called when alloc was invoked.

fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Called when dealloc was invoked.

fn grow(
    &self,
    ptr: NonNull<u8>,
    layout: Layout,
    new_size: usize,
    placement: ReallocPlacement,
    init: AllocInit,
    result: Result<MemoryBlock, AllocErr>
)

Called when grow was invoked.

fn shrink(
    &self,
    ptr: NonNull<u8>,
    layout: Layout,
    new_size: usize,
    placement: ReallocPlacement,
    result: Result<MemoryBlock, AllocErr>
)

Called when shrink was invoked.

fn owns(&self, success: bool)

Called when owns was invoked.

Loading content...

Provided methods

fn by_ref(&self) -> &Self

Creates a "by reference" adaptor for this instance of CallbackRef.

The returned adaptor also implements CallbackRef and will simply borrow this.

Loading content...

Implementations on Foreign Types

impl<C: CallbackRef> CallbackRef for Box<C>[src]

This is only available with the "alloc"-feature enabled.

impl<C: CallbackRef> CallbackRef for Rc<C>[src]

This is only available with the "alloc"-feature enabled.

impl<C: CallbackRef> CallbackRef for Arc<C>[src]

This is only available with the "alloc"-feature enabled.

Loading content...

Implementors

impl CallbackRef for AtomicCounter[src]

impl CallbackRef for Counter[src]

impl CallbackRef for FilteredAtomicCounter[src]

impl CallbackRef for FilteredCounter[src]

impl<'_, C: CallbackRef> CallbackRef for &'_ C[src]

Loading content...