[−][src]Struct cap::Cap
A struct that wraps another allocator and limits the number of bytes that can be allocated.
Methods
impl<H> Cap<H>
[src]
pub const fn new(allocator: H, limit: usize) -> Self
[src]
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()
.
pub fn remaining(&self) -> usize
[src]
Return the number of bytes remaining within the limit.
i.e. limit - allocated
pub fn limit(&self) -> usize
[src]
Return the limit in bytes.
pub fn set_limit(&self, limit: usize) -> Result<(), ()>
[src]
Set the limit in bytes.
For no limit, simply set the limit to the theoretical maximum usize::max_value()
.
This method will return Err
if the specified limit is less than the number of bytes already allocated.
pub fn allocated(&self) -> usize
[src]
Return the number of bytes allocated. Always less than the limit.
Trait Implementations
impl<H: Debug> Debug for Cap<H>
[src]
impl<H> GlobalAlloc for Cap<H> where
H: GlobalAlloc,
[src]
H: GlobalAlloc,
Auto Trait Implementations
impl<H> Send for Cap<H> where
H: Send,
H: Send,
impl<H> Sync for Cap<H> where
H: Sync,
H: Sync,
impl<H> Unpin for Cap<H> where
H: Unpin,
H: Unpin,
impl<H> UnwindSafe for Cap<H> where
H: UnwindSafe,
H: UnwindSafe,
impl<H> RefUnwindSafe for Cap<H> where
H: RefUnwindSafe,
H: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,