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
Allocates memory as described by the given
layout
. Read moreAuto Trait Implementations§
impl<H> !Freeze for Cap<H>
impl<H> RefUnwindSafe for Cap<H>where
H: RefUnwindSafe,
impl<H> Send for Cap<H>where
H: Send,
impl<H> Sync for Cap<H>where
H: Sync,
impl<H> Unpin for Cap<H>where
H: Unpin,
impl<H> UnwindSafe for Cap<H>where
H: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more