Skip to main content

BumpScope

Struct BumpScope 

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

A bump allocation scope.

A BumpScope’s allocations are live for 'a, which is the lifetime of its associated BumpScopeGuard or scoped closure.

BumpScope has mostly same api as Bump.

This type is provided as a parameter to the closure of scoped, or created by BumpScopeGuard::scope. A Bump can also be turned into a BumpScope using as_scope, as_mut_scope or from / into.

Implementations§

Source§

impl<A, S> BumpScope<'_, 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§

impl<'a, A, S> BumpScope<'a, A, S>

Source

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

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

Source

pub fn as_mut_aligned<const NEW_MIN_ALIGN: usize>( &mut self, ) -> &mut BumpScope<'a, A, S::WithMinimumAlignment<NEW_MIN_ALIGN>>

Mutably borrows BumpScope with a new minimum alignment.

This cannot decrease the alignment. Trying to decrease alignment will result in a compile error. You can use aligned or scoped_aligned to decrease the alignment.

When decreasing the alignment we need to make sure that the bump position is realigned to the original alignment. That can only be ensured by having a function that takes a closure, like the methods mentioned above do.

Source

pub fn into_aligned<const NEW_MIN_ALIGN: usize>( self, ) -> BumpScope<'a, A, S::WithMinimumAlignment<NEW_MIN_ALIGN>>

Converts this BumpScope into a BumpScope with a new minimum alignment.

This cannot decrease the alignment. Trying to decrease alignment will result in a compile error. You can use aligned or scoped_aligned to decrease the alignment.

When decreasing the alignment we need to make sure that the bump position is realigned to the original alignment. That can only be ensured by having a function that takes a closure, like the methods mentioned above do.

If this was allowed to decrease the alignment it would break minimum alignment:

let mut bump: Bump<Global, 8, true> = Bump::new();
let mut guard = bump.scope_guard();

{
    let scope = guard.scope().into_aligned::<1>();
    scope.alloc(0u8);
}

{
    let scope = guard.scope();
    // scope is not aligned to `MIN_ALIGN`!!
}
Source

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

Converts this BumpScope into a BumpScope with new settings.

Not all settings can be converted to. 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 borrow_with_settings<NewS>(&self) -> &BumpScope<'a, A, NewS>

Borrows this BumpScope with new settings.

Not all settings can be converted to. 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 borrow_mut_with_settings<NewS>(&mut self) -> &mut BumpScope<'a, A, NewS>

Borrows this BumpScope mutably with new settings.

Not all settings can be converted to. 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§

impl<S> BumpScope<'_, Global, S>

Source

pub fn into_raw(self) -> NonNull<()>

Available on crate feature alloc only.

Converts this BumpScope into a raw pointer.

Source

pub unsafe fn from_raw(ptr: NonNull<()>) -> Self

Available on crate feature alloc only.

Converts the raw pointer that was created with into_raw back into a BumpScope.

§Safety

This is highly unsafe, due to the number of invariants that aren’t checked:

  • ptr must have been created with Self::into_raw.
  • This function must only be called once with this ptr.
  • Nothing must have been allocated since then.
  • The lifetime must match the original one.
  • The settings must match the original ones.
Source§

impl<'a, A, S> BumpScope<'a, A, S>

Methods that forward to traits.

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 allocator(&self) -> &A

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§

impl<'a, A, S> BumpScope<'a, A, S>

Additional alloc methods that are not available in traits.

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, S> Allocator for &mut BumpScope<'_, A, S>

Available on crate feature allocator-api2-03 only.
Source§

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

Attempts to allocate a block of memory. Read more
Source§

unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)

Deallocates the memory referenced by ptr. Read more
Source§

unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

Attempts to extend the memory block. Read more
Source§

unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

Behaves like grow, but also ensures that the new contents are set to zero before being returned. Read more
Source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

Attempts to shrink the memory block. Read more
Source§

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

Behaves like allocate, but also ensures that the returned memory is zero-initialized. Read more
Source§

fn by_ref(&self) -> &Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Allocator. Read more
Source§

impl<A, S> Allocator for BumpScope<'_, A, S>

Source§

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

Attempts to allocate a block of memory. Read more
Source§

unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)

Deallocates the memory referenced by ptr. Read more
Source§

unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>

Attempts to extend the memory block. Read more
Source§

unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>

Behaves like grow, but also ensures that the new contents are set to zero before being returned. Read more
Source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>

Attempts to shrink the memory block. Read more
Source§

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

Behaves like allocate, but also ensures that the returned memory is zero-initialized. Read more
Source§

fn by_ref(&self) -> &Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Allocator. Read more
Source§

impl<A, S> Allocator for BumpScope<'_, A, S>

Available on crate feature nightly-allocator-api only.
Source§

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

🔬This is a nightly-only experimental API. (allocator_api)
Attempts to allocate a block of memory. Read more
Source§

unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)

🔬This is a nightly-only experimental API. (allocator_api)
Deallocates the memory referenced by ptr. Read more
Source§

unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

🔬This is a nightly-only experimental API. (allocator_api)
Attempts to extend the memory block. Read more
Source§

unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

🔬This is a nightly-only experimental API. (allocator_api)
Behaves like grow, but also ensures that the new contents are set to zero before being returned. Read more
Source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

🔬This is a nightly-only experimental API. (allocator_api)
Attempts to shrink the memory block. Read more
Source§

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

🔬This is a nightly-only experimental API. (allocator_api)
Behaves like allocate, but also ensures that the returned memory is zero-initialized. Read more
Source§

fn by_ref(&self) -> &Self
where Self: Sized,

🔬This is a nightly-only experimental API. (allocator_api)
Creates a “by reference” adapter for this instance of Allocator. Read more
Source§

impl<A, S> Allocator for BumpScope<'_, A, S>

Available on crate feature allocator-api2-03 only.
Source§

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

Attempts to allocate a block of memory. Read more
Source§

unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)

Deallocates the memory referenced by ptr. Read more
Source§

unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

Attempts to extend the memory block. Read more
Source§

unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

Behaves like grow, but also ensures that the new contents are set to zero before being returned. Read more
Source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

Attempts to shrink the memory block. Read more
Source§

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

Behaves like allocate, but also ensures that the returned memory is zero-initialized. Read more
Source§

fn by_ref(&self) -> &Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Allocator. Read more
Source§

impl<A, S> Allocator for BumpScope<'_, A, S>

Available on crate feature allocator-api2-04 only.
Source§

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

Attempts to allocate a block of memory. Read more
Source§

unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)

Deallocates the memory referenced by ptr. Read more
Source§

unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

Attempts to extend the memory block. Read more
Source§

unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

Behaves like grow, but also ensures that the new contents are set to zero before being returned. Read more
Source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, TargetAllocError>

Attempts to shrink the memory block. Read more
Source§

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

Behaves like allocate, but also ensures that the returned memory is zero-initialized. Read more
Source§

fn by_ref(&self) -> &Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Allocator. Read more
Source§

impl<A, S> BumpAllocator for BumpScope<'_, A, S>

Source§

type Allocator = A

The base allocator.
Source§

type Settings = S

The bump allocator settings.
Source§

fn as_scope(&self) -> &BumpScope<'_, Self::Allocator, Self::Settings>

Returns this bump allocator as a &BumpScope.
Source§

fn as_mut_scope( &mut self, ) -> &mut BumpScope<'_, Self::Allocator, Self::Settings>

Returns this bump allocator as a &mut BumpScope.
Source§

fn scope_guard(&mut self) -> BumpScopeGuard<'_, Self::Allocator, Self::Settings>

Creates a new BumpScopeGuard. Read more
Source§

fn scoped<R>( &mut self, f: impl FnOnce(&mut BumpScope<'_, Self::Allocator, Self::Settings>) -> R, ) -> R

Calls f with a new child scope. Read more
Source§

fn scoped_aligned<const NEW_MIN_ALIGN: usize, R>( &mut self, f: impl FnOnce(&mut BumpScope<'_, Self::Allocator, <Self::Settings as BumpAllocatorSettings>::WithMinimumAlignment<NEW_MIN_ALIGN>>) -> R, ) -> R

Calls f with a new child scope of a new minimum alignment. Read more
Source§

impl<A, S> BumpAllocatorCore for BumpScope<'_, A, S>

Source§

fn any_stats(&self) -> AnyStats<'_>

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

fn checkpoint(&self) -> Checkpoint

Creates a checkpoint of the current bump position. Read more
Source§

unsafe fn reset_to(&self, checkpoint: Checkpoint)

Resets the bump position to a previously created checkpoint. The memory that has been allocated since then will be reused by future allocations. Read more
Source§

fn is_claimed(&self) -> bool

Returns true if the bump allocator is currently claimed.
Source§

fn prepare_allocation( &self, layout: Layout, ) -> Result<Range<NonNull<u8>>, AllocError>

Returns a pointer range of free space in the bump allocator with a size of at least layout.size(). Read more
Source§

unsafe fn allocate_prepared( &self, layout: Layout, range: Range<NonNull<u8>>, ) -> NonNull<u8>

Allocate part of the free space returned from a prepare_allocation call. Read more
Source§

fn prepare_allocation_rev( &self, layout: Layout, ) -> Result<Range<NonNull<u8>>, AllocError>

Returns a pointer range of free space in the bump allocator with a size of at least layout.size(). Read more
Source§

unsafe fn allocate_prepared_rev( &self, layout: Layout, range: Range<NonNull<u8>>, ) -> NonNull<u8>

Allocate part of the free space returned from a prepare_allocation_rev call starting at the end. Read more
Source§

impl<'a, A, S> BumpAllocatorScope<'a> for BumpScope<'a, A, S>

Source§

fn claim(&self) -> BumpClaimGuard<'_, 'a, Self::Allocator, Self::Settings>

Claims exclusive access to the bump allocator from a shared reference. Read more
Source§

fn stats(&self) -> Stats<'a, Self::Settings>

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

fn aligned<const NEW_MIN_ALIGN: usize, R>( &mut self, f: impl FnOnce(&mut BumpScope<'a, Self::Allocator, <Self::Settings as BumpAllocatorSettings>::WithMinimumAlignment<NEW_MIN_ALIGN>>) -> R, ) -> R

Calls f with this scope but with a new minimum alignment. Read more
Source§

fn allocator(&self) -> &Self::Allocator

Returns a reference to the base allocator.
Source§

impl<A, S> BumpAllocatorTyped for BumpScope<'_, A, S>

Source§

type TypedStats<'b> = Stats<'b, S> where Self: 'b

The type returned by the stats method.
Source§

fn typed_stats(&self) -> Self::TypedStats<'_>

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

fn allocate_layout(&self, layout: Layout) -> NonNull<u8>

A specialized version of allocate. Read more
Source§

fn try_allocate_layout(&self, layout: Layout) -> Result<NonNull<u8>, AllocError>

A specialized version of allocate. Read more
Source§

fn allocate_sized<T>(&self) -> NonNull<T>

A specialized version of allocate. Read more
Source§

fn try_allocate_sized<T>(&self) -> Result<NonNull<T>, AllocError>

A specialized version of allocate. Read more
Source§

fn allocate_slice<T>(&self, len: usize) -> NonNull<T>

A specialized version of allocate. Read more
Source§

fn try_allocate_slice<T>(&self, len: usize) -> Result<NonNull<T>, AllocError>

A specialized version of allocate. Read more
Source§

fn allocate_slice_for<T>(&self, slice: &[T]) -> NonNull<T>

A specialized version of allocate. Read more
Source§

fn try_allocate_slice_for<T>( &self, slice: &[T], ) -> Result<NonNull<T>, AllocError>

A specialized version of allocate. Read more
Source§

unsafe fn shrink_slice<T>( &self, ptr: NonNull<T>, old_len: usize, new_len: usize, ) -> Option<NonNull<T>>

A specialized version of shrink. Read more
Source§

fn prepare_slice_allocation<T>(&self, len: usize) -> NonNull<[T]>

A specialized version of prepare_allocation. Read more
Source§

fn try_prepare_slice_allocation<T>( &self, len: usize, ) -> Result<NonNull<[T]>, AllocError>

A specialized version of prepare_allocation. Read more
Source§

unsafe fn allocate_prepared_slice<T>( &self, start: NonNull<T>, len: usize, cap: usize, ) -> NonNull<[T]>

A specialized version of allocate_prepared. Read more
Source§

fn prepare_slice_allocation_rev<T>(&self, len: usize) -> (NonNull<T>, usize)

A specialized version of prepare_allocation_rev. Read more
Source§

fn try_prepare_slice_allocation_rev<T>( &self, len: usize, ) -> Result<(NonNull<T>, usize), AllocError>

A specialized version of prepare_allocation_rev. Read more
Source§

unsafe fn allocate_prepared_slice_rev<T>( &self, end: NonNull<T>, len: usize, cap: usize, ) -> NonNull<[T]>

A specialized version of allocate_prepared_rev. Read more
Source§

fn reserve(&self, additional: usize)

Reserves capacity for at least additional more bytes to be bump allocated. The bump allocator may reserve more space to avoid frequent reallocations. After calling reserve, self.stats().remaining() will be greater than or equal to additional. Does nothing if the capacity is already sufficient. Read more
Source§

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

Reserves capacity for at least additional more bytes to be bump allocated. The bump allocator may reserve more space to avoid frequent reallocations. After calling reserve, self.stats().remaining() will be greater than or equal to additional. Does nothing if the capacity is already sufficient. Read more
Source§

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

Drops an allocated value and attempts to free its memory. Read more
Source§

impl<A, S> Debug for BumpScope<'_, A, S>

Source§

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

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

impl<'b, A, S> From<&'b Bump<A, S>> for &'b BumpScope<'b, A, S>

Source§

fn from(value: &'b Bump<A, S>) -> Self

Converts to this type from the input type.
Source§

impl<'b, A, S> From<&'b mut Bump<A, S>> for &'b mut BumpScope<'b, A, S>

Source§

fn from(value: &'b mut Bump<A, S>) -> Self

Converts to this type from the input type.
Source§

impl<'a, A, S> BumpAllocatorCoreScope<'a> for BumpScope<'a, A, S>

Source§

impl<A, S> MutBumpAllocatorCore for BumpScope<'_, A, S>

Source§

impl<A, S> NoDrop for BumpScope<'_, A, S>

Source§

impl<A, S> RefUnwindSafe for BumpScope<'_, A, S>

Source§

impl<A, S> UnwindSafe for BumpScope<'_, A, S>

Auto Trait Implementations§

§

impl<'a, A = Global, S = BumpSettings> !Freeze for BumpScope<'a, A, S>

§

impl<'a, A = Global, S = BumpSettings> !Send for BumpScope<'a, A, S>

§

impl<'a, A = Global, S = BumpSettings> !Sync for BumpScope<'a, A, S>

§

impl<'a, A, S> Unpin for BumpScope<'a, A, S>
where A: Unpin,

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<'a, B> BumpAllocatorTypedScope<'a> for B

Source§

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

Allocate an object. Read more
Source§

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

Allocate an object. Read more
Source§

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

Allocates space for an object, then calls f to produce the value to be put in that place. Read more
Source§

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

Allocates space for an object, then calls f to produce the value to be put in that place. Read more
Source§

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

Allocate an object with its default value. Read more
Source§

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

Allocate an object with its default value. Read more
Source§

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

Available on crate feature nightly-clone-to-uninit only.
Allocate an object by cloning it. Read more
Source§

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

Available on crate feature nightly-clone-to-uninit only.
Allocate an object by cloning it. Read more
Source§

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

Allocate an uninitialized object. Read more
Source§

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

Allocate an uninitialized object. Read more
Source§

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

Allocate a slice and fill it by moving elements from an existing slice. Read more
Source§

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

Allocate a slice and fill it by moving elements from an existing slice. Read more
Source§

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

Allocate a slice and fill it by Copying elements from an existing slice. Read more
Source§

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

Allocate a slice and fill it by Copying elements from an existing slice. Read more
Source§

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

Allocate a slice and fill it by Cloneing elements from an existing slice. Read more
Source§

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

Allocate a slice and fill it by Cloneing elements from an existing slice. Read more
Source§

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

Allocate a slice and fill it with elements by cloning value. Read more
Source§

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

Allocate a slice and fill it with elements by cloning value. Read more
Source§

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

Allocates a slice by fill it with elements returned by calling a closure repeatedly. Read more
Source§

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

Allocates a slice by fill it with elements returned by calling a closure repeatedly. Read more
Source§

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

Allocate an uninitialized object slice. Read more
Source§

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

Allocate an uninitialized object slice. Read more
Source§

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

Allocate an uninitialized object slice. Read more
Source§

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

Allocate an uninitialized object slice. Read more
Source§

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

Allocate a str. Read more
Source§

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

Allocate a str. Read more
Source§

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

Allocate a str from format arguments. Read more
Source§

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

Allocate a str from format arguments. Read more
Source§

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

Allocate a CStr. Read more
Source§

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

Allocate a CStr. Read more
Source§

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

Allocate a CStr from a str. Read more
Source§

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

Allocate a CStr from a str. Read more
Source§

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

Allocate a CStr from format arguments. Read more
Source§

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

Allocate a CStr from format arguments. Read more
Source§

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

Allocate elements of an iterator into a slice. Read more
Source§

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

Allocate elements of an iterator into a slice. Read more
Source§

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

Allocate elements of an ExactSizeIterator into a slice. Read more
Source§

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>,

Allocate elements of an ExactSizeIterator into a slice. Read more
Source§

impl<'a, T> BumpAllocatorTypedScopeExt<'a> for T

Source§

fn alloc_zeroed<T>(&self) -> BumpBox<'a, T>
where T: Zeroable,

Allocate a zeroed object. Read more
Source§

fn try_alloc_zeroed<T>(&self) -> Result<BumpBox<'a, T>, AllocError>
where T: Zeroable,

Allocate a zeroed object. Read more
Source§

fn alloc_zeroed_slice<T>(&self, len: usize) -> BumpBox<'a, [T]>
where T: Zeroable,

Allocate a zeroed object slice. Read more
Source§

fn try_alloc_zeroed_slice<T>( &self, len: usize, ) -> Result<BumpBox<'a, [T]>, AllocError>
where T: Zeroable,

Allocate a zeroed object slice. Read more
Source§

impl<'a, T> BumpAllocatorTypedScopeExt<'a> for T

Source§

fn alloc_zeroed<T>(&self) -> BumpBox<'a, T>
where T: FromZeros,

Allocate a zeroed object. Read more
Source§

fn try_alloc_zeroed<T>(&self) -> Result<BumpBox<'a, T>, AllocError>
where T: FromZeros,

Allocate a zeroed object. Read more
Source§

fn alloc_zeroed_slice<T>(&self, len: usize) -> BumpBox<'a, [T]>
where T: FromZeros,

Allocate a zeroed object slice. Read more
Source§

fn try_alloc_zeroed_slice<T>( &self, len: usize, ) -> Result<BumpBox<'a, [T]>, AllocError>
where T: FromZeros,

Allocate a zeroed object slice. 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<'a, A> MutBumpAllocatorTypedScope<'a> for A

Source§

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

Allocate elements of an iterator into a slice. Read more
Source§

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

Allocate elements of an iterator into a slice. Read more
Source§

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

Allocate elements of an iterator into a slice in reverse order. Read more
Source§

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

Allocate elements of an iterator into a slice in reverse order. Read more
Source§

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

Allocate a str from format arguments. Read more
Source§

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

Allocate a str from format arguments. Read more
Source§

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

Allocate a CStr from format arguments. Read more
Source§

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

Allocate a CStr from format arguments. Read more
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.
Source§

impl<'a, B> MutBumpAllocatorCoreScope<'a> for B

Source§

impl<A> MutBumpAllocatorTyped for A