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