Trait Allocator

Source
pub unsafe trait Allocator {
    // Required methods
    fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, Error>;
    unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout);

    // Provided method
    fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, Error> { ... }
}
Expand description

A subset of the features of std::alloc::Allocator which is experimental. Changed the error types to anyhow::Error so we can forward libbpf_rs errors. This will likely need to be the empty struct std::alloc::AllocError if we migrate to the official trait (and panic accordingly).

§Safety

See https://doc.rust-lang.org/std/alloc/trait.Allocator.html#safety

Required Methods§

Source

fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, Error>

Source

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

§Safety

See https://doc.rust-lang.org/std/alloc/trait.Allocator.html#safety-1

Provided Methods§

Source

fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, Error>

Implementors§

Source§

impl<T> Allocator for HeapAllocator<T>
where T: Allocator,