[][src]Struct cap::Cap

pub struct Cap<H> { /* fields omitted */ }

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]

Auto Trait Implementations

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

impl<H> RefUnwindSafe for Cap<H> where
    H: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]