Struct Bump

Source
pub struct Bump<A: BackingAllocator> { /* private fields */ }
Expand description

A bump allocator.

For a general discussion of bump allocation, see the module-level documentation.

Implementations§

Source§

impl Bump<Raw>

Source

pub unsafe fn new_raw( region: NonNull<u8>, layout: Layout, ) -> Result<Bump<Raw>, AllocInitError>

Constructs a new Bump from a raw pointer.

§Safety

The caller must uphold the following invariants:

  • region must be a pointer to a region that fits layout, and it must be valid for reads and writes for the entire size indicated by layout.
  • No references to the memory at region may exist when this function is called.
  • As long as the returned Bump exists, no accesses may be made to the memory at region except by way of methods on the returned Bump.
Source§

impl Bump<Global>

Source

pub fn try_new(layout: Layout) -> Result<Bump<Global>, AllocInitError>

Available on crate feature alloc only.

Attempts to construct a new Bump backed by the global allocator.

The memory managed by this Bump is allocated from the global allocator according to layout.

§Errors

Returns an error if sufficient memory could not be allocated from the global allocator.

Source§

impl<A> Bump<A>
where A: Allocator,

Source

pub fn try_new_in( layout: Layout, backing_allocator: A, ) -> Result<Bump<A>, AllocInitError>

Available on crate feature unstable only.

Attempts to construct a new Bump backed by backing_allocator.

The memory managed by this Bump is allocated from backing_allocator according to layout.

§Errors

Returns an error if sufficient memory could not be allocated from backing_allocator.

Source§

impl<A> Bump<A>

Source

pub fn allocate(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>

Attempts to allocate a block of memory according to layout.

§Errors

Returns Err if there is insufficient memory remaining to accommodate layout.

Source

pub unsafe fn deallocate(&mut self, ptr: NonNull<u8>)

Deallocates a block of memory.

This operation does not increase the amount of available memory unless ptr is the last outstanding allocation from this allocator.

§Safety

ptr must denote a block of memory currently allocated via this allocator.

Source

pub unsafe fn reset(&mut self)

Resets the bump allocator.

This method invalidates all outstanding allocations from this allocator. The destructors of allocated objects will not be run.

§Safety

The caller must uphold the following invariants:

  • No references to memory allocated by this Bump may exist when the method is called.
  • Any pointers to memory previously allocated by this allocator may no longer be dereferenced or passed to Bump::deallocate().

Trait Implementations§

Source§

impl<A> Debug for Bump<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A> Drop for Bump<A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<A> Freeze for Bump<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for Bump<A>
where A: RefUnwindSafe,

§

impl<A> !Send for Bump<A>

§

impl<A> !Sync for Bump<A>

§

impl<A> Unpin for Bump<A>
where A: Unpin,

§

impl<A> UnwindSafe for Bump<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.