pub struct Cap<H> { /* private fields */ }
Expand description
A struct that wraps another allocator and limits the number of bytes that can be allocated.
Implementations§
source§impl<H> Cap<H>
impl<H> Cap<H>
sourcepub const fn new(allocator: H, limit: usize) -> Self
pub const fn new(allocator: H, limit: usize) -> Self
Create a new allocator, wrapping the supplied allocator and enforcing the specified limit.
For no limit, simply set the limit to the theoretical maximum usize::max_value()
.
sourcepub fn remaining(&self) -> usize
pub fn remaining(&self) -> usize
Return the number of bytes remaining within the limit.
i.e. limit - allocated
Trait Implementations§
source§impl<H> GlobalAlloc for Cap<H>where
H: GlobalAlloc,
impl<H> GlobalAlloc for Cap<H>where H: GlobalAlloc,
source§unsafe fn alloc(&self, l: Layout) -> *mut u8
unsafe fn alloc(&self, l: Layout) -> *mut u8
Allocate memory as described by the given
layout
. Read more