Skip to main content

BumpClaimGuard

Struct BumpClaimGuard 

Source
pub struct BumpClaimGuard<'b, 'a, A, S = BumpSettings>{ /* private fields */ }
Expand description

Methods from Deref<Target = BumpScope<'a, A, S>>§

Source

pub fn by_value(&mut self) -> BumpScope<'_, A, S>

Returns this &mut BumpScope as a BumpScope.

This requires allocating a chunk if none has been allocated yet.

This method exists so you can have BumpScope<'a> function parameters and struct fields instead of &'b mut BumpScope<'a> so you don’t have to deal with 'b.

It also enables more settings conversions since with_settings can do more than borrow_mut_with_settings.

§Panics

Panics if the bump allocator is currently claimed.

Panics if the allocation fails.

Source

pub fn try_by_value(&mut self) -> Result<BumpScope<'_, A, S>, AllocError>

Returns this &mut BumpScope as a BumpScope.

This requires allocating a chunk if none has been allocated yet.

This method exists so you can have BumpScope<'a> function parameters and struct fields instead of &'b mut BumpScope<'a> so you don’t have to deal with 'b.

It also enables more settings conversions since with_settings can do more than borrow_mut_with_settings.

§Errors

Errors if the bump allocator is currently claimed.

Errors if the allocation fails.

Source

pub fn stats(&self) -> Stats<'a, A, S>

Returns a type which provides statistics about the memory usage of the bump allocator.

Source

pub fn allocator(&self) -> Option<&'a A>

Returns a reference to the base allocator.

Source

pub fn borrow_with_settings<NewS>(&self) -> &BumpScope<'a, A, NewS>

Borrows this BumpScope with new settings.

This function will fail to compile if:

  • NewS::MIN_ALIGN != S::MIN_ALIGN
  • NewS::UP != S::UP
  • NewS::CLAIMABLE != S::CLAIMABLE
  • NewS::GUARANTEED_ALLOCATED > S::GUARANTEED_ALLOCATED
Source

pub fn borrow_mut_with_settings<NewS>(&mut self) -> &mut BumpScope<'a, A, NewS>

Borrows this BumpScope mutably with new settings.

This function will fail to compile if:

  • NewS::MIN_ALIGN < S::MIN_ALIGN
  • NewS::UP != S::UP
  • NewS::GUARANTEED_ALLOCATED != S::GUARANTEED_ALLOCATED
  • NewS::CLAIMABLE != S::CLAIMABLE
Source

pub fn claim(&self) -> BumpClaimGuard<'_, 'a, A, S>

Source

pub fn is_claimed(&self) -> bool

Source

pub fn scope_guard(&mut self) -> BumpScopeGuard<'_, A, S>

Source

pub fn scoped<R>(&mut self, f: impl FnOnce(&mut BumpScope<'_, A, S>) -> R) -> R

Forwards to BumpAllocator::scoped.

Source

pub fn scoped_aligned<const NEW_MIN_ALIGN: usize, R>( &mut self, f: impl FnOnce(&mut BumpScope<'_, A, S::WithMinimumAlignment<NEW_MIN_ALIGN>>) -> R, ) -> R

Source

pub fn aligned<const NEW_MIN_ALIGN: usize, R>( &mut self, f: impl FnOnce(&mut BumpScope<'a, A, S::WithMinimumAlignment<NEW_MIN_ALIGN>>) -> R, ) -> R

Source

pub fn checkpoint(&self) -> Checkpoint

Source

pub unsafe fn reset_to(&self, checkpoint: Checkpoint)

Source

pub fn alloc<T>(&self, value: T) -> BumpBox<'a, T>

Source

pub fn try_alloc<T>(&self, value: T) -> Result<BumpBox<'a, T>, AllocError>

Source

pub fn alloc_with<T>(&self, f: impl FnOnce() -> T) -> BumpBox<'a, T>

Source

pub fn try_alloc_with<T>( &self, f: impl FnOnce() -> T, ) -> Result<BumpBox<'a, T>, AllocError>

Source

pub fn alloc_default<T: Default>(&self) -> BumpBox<'a, T>

Source

pub fn try_alloc_default<T: Default>( &self, ) -> Result<BumpBox<'a, T>, AllocError>

Source

pub fn alloc_clone<T: CloneToUninit + ?Sized>( &self, value: &T, ) -> BumpBox<'a, T>

Available on crate feature nightly-clone-to-uninit only.
Source

pub fn try_alloc_clone<T: CloneToUninit + ?Sized>( &self, value: &T, ) -> Result<BumpBox<'a, T>, AllocError>

Available on crate feature nightly-clone-to-uninit only.
Source

pub fn alloc_slice_move<T>( &self, slice: impl OwnedSlice<Item = T>, ) -> BumpBox<'a, [T]>

Source

pub fn try_alloc_slice_move<T>( &self, slice: impl OwnedSlice<Item = T>, ) -> Result<BumpBox<'a, [T]>, AllocError>

Source

pub fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> BumpBox<'a, [T]>

Source

pub fn try_alloc_slice_copy<T: Copy>( &self, slice: &[T], ) -> Result<BumpBox<'a, [T]>, AllocError>

Source

pub fn alloc_slice_clone<T: Clone>(&self, slice: &[T]) -> BumpBox<'a, [T]>

Source

pub fn try_alloc_slice_clone<T: Clone>( &self, slice: &[T], ) -> Result<BumpBox<'a, [T]>, AllocError>

Source

pub fn alloc_slice_fill<T: Clone>( &self, len: usize, value: T, ) -> BumpBox<'a, [T]>

Source

pub fn try_alloc_slice_fill<T: Clone>( &self, len: usize, value: T, ) -> Result<BumpBox<'a, [T]>, AllocError>

Source

pub fn alloc_slice_fill_with<T>( &self, len: usize, f: impl FnMut() -> T, ) -> BumpBox<'a, [T]>

Source

pub fn try_alloc_slice_fill_with<T>( &self, len: usize, f: impl FnMut() -> T, ) -> Result<BumpBox<'a, [T]>, AllocError>

Source

pub fn alloc_str(&self, src: &str) -> BumpBox<'a, str>

Source

pub fn try_alloc_str(&self, src: &str) -> Result<BumpBox<'a, str>, AllocError>

Source

pub fn alloc_fmt(&self, args: Arguments<'_>) -> BumpBox<'a, str>

Source

pub fn try_alloc_fmt( &self, args: Arguments<'_>, ) -> Result<BumpBox<'a, str>, AllocError>

Source

pub fn alloc_fmt_mut(&mut self, args: Arguments<'_>) -> BumpBox<'a, str>

Source

pub fn try_alloc_fmt_mut( &mut self, args: Arguments<'_>, ) -> Result<BumpBox<'a, str>, AllocError>

Source

pub fn alloc_cstr(&self, src: &CStr) -> &'a CStr

Source

pub fn try_alloc_cstr(&self, src: &CStr) -> Result<&'a CStr, AllocError>

Source

pub fn alloc_cstr_from_str(&self, src: &str) -> &'a CStr

Source

pub fn try_alloc_cstr_from_str(&self, src: &str) -> Result<&'a CStr, AllocError>

Source

pub fn alloc_cstr_fmt(&self, args: Arguments<'_>) -> &'a CStr

Source

pub fn try_alloc_cstr_fmt( &self, args: Arguments<'_>, ) -> Result<&'a CStr, AllocError>

Source

pub fn alloc_cstr_fmt_mut(&mut self, args: Arguments<'_>) -> &'a CStr

Source

pub fn try_alloc_cstr_fmt_mut( &mut self, args: Arguments<'_>, ) -> Result<&'a CStr, AllocError>

Source

pub fn alloc_iter<T>( &self, iter: impl IntoIterator<Item = T>, ) -> BumpBox<'a, [T]>

Source

pub fn try_alloc_iter<T>( &self, iter: impl IntoIterator<Item = T>, ) -> Result<BumpBox<'a, [T]>, AllocError>

Source

pub fn alloc_iter_exact<T, I>( &self, iter: impl IntoIterator<Item = T, IntoIter = I>, ) -> BumpBox<'a, [T]>
where I: ExactSizeIterator<Item = T>,

Source

pub fn try_alloc_iter_exact<T, I>( &self, iter: impl IntoIterator<Item = T, IntoIter = I>, ) -> Result<BumpBox<'a, [T]>, AllocError>
where I: ExactSizeIterator<Item = T>,

Source

pub fn alloc_iter_mut<T>( &mut self, iter: impl IntoIterator<Item = T>, ) -> BumpBox<'a, [T]>

Source

pub fn try_alloc_iter_mut<T>( &mut self, iter: impl IntoIterator<Item = T>, ) -> Result<BumpBox<'a, [T]>, AllocError>

Source

pub fn alloc_iter_mut_rev<T>( &mut self, iter: impl IntoIterator<Item = T>, ) -> BumpBox<'a, [T]>

Source

pub fn try_alloc_iter_mut_rev<T>( &mut self, iter: impl IntoIterator<Item = T>, ) -> Result<BumpBox<'a, [T]>, AllocError>

Source

pub fn alloc_uninit<T>(&self) -> BumpBox<'a, MaybeUninit<T>>

Source

pub fn try_alloc_uninit<T>( &self, ) -> Result<BumpBox<'a, MaybeUninit<T>>, AllocError>

Source

pub fn alloc_uninit_slice<T>(&self, len: usize) -> BumpBox<'a, [MaybeUninit<T>]>

Source

pub fn try_alloc_uninit_slice<T>( &self, len: usize, ) -> Result<BumpBox<'a, [MaybeUninit<T>]>, AllocError>

Source

pub fn alloc_uninit_slice_for<T>( &self, slice: &[T], ) -> BumpBox<'a, [MaybeUninit<T>]>

Source

pub fn try_alloc_uninit_slice_for<T>( &self, slice: &[T], ) -> Result<BumpBox<'a, [MaybeUninit<T>]>, AllocError>

Source

pub fn dealloc<T: ?Sized>(&self, boxed: BumpBox<'_, T>)

Source

pub fn reserve(&self, additional: usize)

Source

pub fn try_reserve(&self, additional: usize) -> Result<(), AllocError>

Source

pub fn alloc_try_with<T, E>( &self, f: impl FnOnce() -> Result<T, E>, ) -> Result<BumpBox<'a, T>, E>

Allocates the result of f in the bump allocator, then moves E out of it and deallocates the space it took up.

This can be more performant than allocating T after the fact, as Result<T, E> may be constructed in the bump allocators memory instead of on the stack and then copied over.

There is also alloc_try_with_mut, optimized for a mutable reference.

§Panics

Panics if the allocation fails.

§Examples
let result = bump.alloc_try_with(|| -> Result<i32, i32> { Ok(123) });
assert_eq!(result.unwrap(), 123);
assert_eq!(bump.stats().allocated(), offset_of!(Result<i32, i32>, Ok.0) + size_of::<i32>());
let result = bump.alloc_try_with(|| -> Result<i32, i32> { Err(123) });
assert_eq!(result.unwrap_err(), 123);
assert_eq!(bump.stats().allocated(), 0);
Source

pub fn try_alloc_try_with<T, E>( &self, f: impl FnOnce() -> Result<T, E>, ) -> Result<Result<BumpBox<'a, T>, E>, AllocError>

Allocates the result of f in the bump allocator, then moves E out of it and deallocates the space it took up.

This can be more performant than allocating T after the fact, as Result<T, E> may be constructed in the bump allocators memory instead of on the stack and then copied over.

There is also try_alloc_try_with_mut, optimized for a mutable reference.

§Errors

Errors if the allocation fails.

§Examples
let result = bump.try_alloc_try_with(|| -> Result<i32, i32> { Ok(123) })?;
assert_eq!(result.unwrap(), 123);
assert_eq!(bump.stats().allocated(), offset_of!(Result<i32, i32>, Ok.0) + size_of::<i32>());
let result = bump.try_alloc_try_with(|| -> Result<i32, i32> { Err(123) })?;
assert_eq!(result.unwrap_err(), 123);
assert_eq!(bump.stats().allocated(), 0);
Source

pub fn alloc_try_with_mut<T, E>( &mut self, f: impl FnOnce() -> Result<T, E>, ) -> Result<BumpBox<'a, T>, E>

Allocates the result of f in the bump allocator, then moves E out of it and deallocates the space it took up.

This can be more performant than allocating T after the fact, as Result<T, E> may be constructed in the bump allocators memory instead of on the stack and then copied over.

This is just like alloc_try_with, but optimized for a mutable reference.

§Panics

Panics if the allocation fails.

§Examples
let result = bump.alloc_try_with_mut(|| -> Result<i32, i32> { Ok(123) });
assert_eq!(result.unwrap(), 123);
assert_eq!(bump.stats().allocated(), offset_of!(Result<i32, i32>, Ok.0) + size_of::<i32>());
let result = bump.alloc_try_with_mut(|| -> Result<i32, i32> { Err(123) });
assert_eq!(result.unwrap_err(), 123);
assert_eq!(bump.stats().allocated(), 0);
Source

pub fn try_alloc_try_with_mut<T, E>( &mut self, f: impl FnOnce() -> Result<T, E>, ) -> Result<Result<BumpBox<'a, T>, E>, AllocError>

Allocates the result of f in the bump allocator, then moves E out of it and deallocates the space it took up.

This can be more performant than allocating T after the fact, as Result<T, E> may be constructed in the bump allocators memory instead of on the stack and then copied over.

This is just like try_alloc_try_with, but optimized for a mutable reference.

§Errors

Errors if the allocation fails.

§Examples
let result = bump.try_alloc_try_with_mut(|| -> Result<i32, i32> { Ok(123) })?;
assert_eq!(result.unwrap(), 123);
assert_eq!(bump.stats().allocated(), offset_of!(Result<i32, i32>, Ok.0) + size_of::<i32>());
let result = bump.try_alloc_try_with_mut(|| -> Result<i32, i32> { Err(123) })?;
assert_eq!(result.unwrap_err(), 123);
assert_eq!(bump.stats().allocated(), 0);

Trait Implementations§

Source§

impl<'a, A, S> Deref for BumpClaimGuard<'_, 'a, A, S>

Source§

type Target = BumpScope<'a, A, S>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<A, S> DerefMut for BumpClaimGuard<'_, '_, A, S>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<A, S> Drop for BumpClaimGuard<'_, '_, A, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'b, 'a, A, S = BumpSettings> !Freeze for BumpClaimGuard<'b, 'a, A, S>

§

impl<'b, 'a, A, S> RefUnwindSafe for BumpClaimGuard<'b, 'a, A, S>
where A: RefUnwindSafe,

§

impl<'b, 'a, A, S = BumpSettings> !Send for BumpClaimGuard<'b, 'a, A, S>

§

impl<'b, 'a, A, S = BumpSettings> !Sync for BumpClaimGuard<'b, 'a, A, S>

§

impl<'b, 'a, A, S> Unpin for BumpClaimGuard<'b, 'a, A, S>

§

impl<'b, 'a, A, S> UnwindSafe for BumpClaimGuard<'b, 'a, A, S>
where A: RefUnwindSafe,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.