pub struct BumpClaimGuard<'b, 'a, A, S = BumpSettings>{ /* private fields */ }Expand description
Returned from BumpAllocatorScope::claim.
Methods from Deref<Target = BumpScope<'a, A, S>>§
Sourcepub fn by_value(&mut self) -> BumpScope<'_, A, S>
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.
Sourcepub fn try_by_value(&mut self) -> Result<BumpScope<'_, A, S>, AllocError>
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.
Sourcepub fn stats(&self) -> Stats<'a, A, S>
pub fn stats(&self) -> Stats<'a, A, S>
Returns a type which provides statistics about the memory usage of the bump allocator.
Sourcepub fn borrow_with_settings<NewS>(&self) -> &BumpScope<'a, A, NewS>where
NewS: BumpAllocatorSettings,
pub fn borrow_with_settings<NewS>(&self) -> &BumpScope<'a, A, NewS>where
NewS: BumpAllocatorSettings,
Borrows this BumpScope with new settings.
This function will fail to compile if:
NewS::MIN_ALIGN != S::MIN_ALIGNNewS::UP != S::UPNewS::CLAIMABLE != S::CLAIMABLENewS::GUARANTEED_ALLOCATED > S::GUARANTEED_ALLOCATED
Sourcepub fn borrow_mut_with_settings<NewS>(&mut self) -> &mut BumpScope<'a, A, NewS>where
NewS: BumpAllocatorSettings,
pub fn borrow_mut_with_settings<NewS>(&mut self) -> &mut BumpScope<'a, A, NewS>where
NewS: BumpAllocatorSettings,
Borrows this BumpScope mutably with new settings.
This function will fail to compile if:
NewS::MIN_ALIGN < S::MIN_ALIGNNewS::UP != S::UPNewS::GUARANTEED_ALLOCATED != S::GUARANTEED_ALLOCATEDNewS::CLAIMABLE != S::CLAIMABLE
Sourcepub fn claim(&self) -> BumpClaimGuard<'_, 'a, A, S>
pub fn claim(&self) -> BumpClaimGuard<'_, 'a, A, S>
Forwards to BumpAllocatorScope::claim.
Sourcepub fn is_claimed(&self) -> bool
pub fn is_claimed(&self) -> bool
Forwards to BumpAllocatorCore::is_claimed.
Sourcepub fn scope_guard(&mut self) -> BumpScopeGuard<'_, A, S>
pub fn scope_guard(&mut self) -> BumpScopeGuard<'_, A, S>
Forwards to BumpAllocator::scope_guard.
Sourcepub fn scoped<R>(&mut self, f: impl FnOnce(&mut BumpScope<'_, A, S>) -> R) -> R
pub fn scoped<R>(&mut self, f: impl FnOnce(&mut BumpScope<'_, A, S>) -> R) -> R
Forwards to BumpAllocator::scoped.
Sourcepub fn scoped_aligned<const NEW_MIN_ALIGN: usize, R>(
&mut self,
f: impl FnOnce(&mut BumpScope<'_, A, S::WithMinimumAlignment<NEW_MIN_ALIGN>>) -> R,
) -> Rwhere
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
pub fn scoped_aligned<const NEW_MIN_ALIGN: usize, R>(
&mut self,
f: impl FnOnce(&mut BumpScope<'_, A, S::WithMinimumAlignment<NEW_MIN_ALIGN>>) -> R,
) -> Rwhere
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
Forwards to BumpAllocator::scoped_aligned.
Sourcepub fn aligned<const NEW_MIN_ALIGN: usize, R>(
&mut self,
f: impl FnOnce(&mut BumpScope<'a, A, S::WithMinimumAlignment<NEW_MIN_ALIGN>>) -> R,
) -> Rwhere
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
pub fn aligned<const NEW_MIN_ALIGN: usize, R>(
&mut self,
f: impl FnOnce(&mut BumpScope<'a, A, S::WithMinimumAlignment<NEW_MIN_ALIGN>>) -> R,
) -> Rwhere
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
Forwards to BumpAllocatorScope::aligned.
Sourcepub fn checkpoint(&self) -> Checkpoint
pub fn checkpoint(&self) -> Checkpoint
Forwards to BumpAllocatorCore::checkpoint.
Sourcepub unsafe fn reset_to(&self, checkpoint: Checkpoint)
pub unsafe fn reset_to(&self, checkpoint: Checkpoint)
Forwards to BumpAllocatorCore::reset_to.
Sourcepub fn alloc<T>(&self, value: T) -> BumpBox<'a, T> ⓘ
pub fn alloc<T>(&self, value: T) -> BumpBox<'a, T> ⓘ
Forwards to BumpAllocatorTypedScope::alloc.
Sourcepub fn try_alloc<T>(&self, value: T) -> Result<BumpBox<'a, T>, AllocError>
pub fn try_alloc<T>(&self, value: T) -> Result<BumpBox<'a, T>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc.
Sourcepub fn alloc_with<T>(&self, f: impl FnOnce() -> T) -> BumpBox<'a, T> ⓘ
pub fn alloc_with<T>(&self, f: impl FnOnce() -> T) -> BumpBox<'a, T> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_with.
Sourcepub fn try_alloc_with<T>(
&self,
f: impl FnOnce() -> T,
) -> Result<BumpBox<'a, T>, AllocError>
pub fn try_alloc_with<T>( &self, f: impl FnOnce() -> T, ) -> Result<BumpBox<'a, T>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_with.
Sourcepub fn alloc_default<T: Default>(&self) -> BumpBox<'a, T> ⓘ
pub fn alloc_default<T: Default>(&self) -> BumpBox<'a, T> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_default.
Sourcepub fn try_alloc_default<T: Default>(
&self,
) -> Result<BumpBox<'a, T>, AllocError>
pub fn try_alloc_default<T: Default>( &self, ) -> Result<BumpBox<'a, T>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_default.
Sourcepub fn alloc_clone<T: CloneToUninit + ?Sized>(
&self,
value: &T,
) -> BumpBox<'a, T> ⓘ
Available on crate feature nightly-clone-to-uninit only.
pub fn alloc_clone<T: CloneToUninit + ?Sized>( &self, value: &T, ) -> BumpBox<'a, T> ⓘ
nightly-clone-to-uninit only.Forwards to BumpAllocatorTypedScope::alloc_clone.
Sourcepub fn try_alloc_clone<T: CloneToUninit + ?Sized>(
&self,
value: &T,
) -> Result<BumpBox<'a, T>, AllocError>
Available on crate feature nightly-clone-to-uninit only.
pub fn try_alloc_clone<T: CloneToUninit + ?Sized>( &self, value: &T, ) -> Result<BumpBox<'a, T>, AllocError>
nightly-clone-to-uninit only.Forwards to BumpAllocatorTypedScope::try_alloc_clone.
Sourcepub fn alloc_slice_move<T>(
&self,
slice: impl OwnedSlice<Item = T>,
) -> BumpBox<'a, [T]> ⓘ
pub fn alloc_slice_move<T>( &self, slice: impl OwnedSlice<Item = T>, ) -> BumpBox<'a, [T]> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_slice_move.
Sourcepub fn try_alloc_slice_move<T>(
&self,
slice: impl OwnedSlice<Item = T>,
) -> Result<BumpBox<'a, [T]>, AllocError>
pub fn try_alloc_slice_move<T>( &self, slice: impl OwnedSlice<Item = T>, ) -> Result<BumpBox<'a, [T]>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_slice_move.
Sourcepub fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> BumpBox<'a, [T]> ⓘ
pub fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> BumpBox<'a, [T]> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_slice_copy.
Sourcepub fn try_alloc_slice_copy<T: Copy>(
&self,
slice: &[T],
) -> Result<BumpBox<'a, [T]>, AllocError>
pub fn try_alloc_slice_copy<T: Copy>( &self, slice: &[T], ) -> Result<BumpBox<'a, [T]>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_slice_copy.
Sourcepub fn alloc_slice_clone<T: Clone>(&self, slice: &[T]) -> BumpBox<'a, [T]> ⓘ
pub fn alloc_slice_clone<T: Clone>(&self, slice: &[T]) -> BumpBox<'a, [T]> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_slice_clone.
Sourcepub fn try_alloc_slice_clone<T: Clone>(
&self,
slice: &[T],
) -> Result<BumpBox<'a, [T]>, AllocError>
pub fn try_alloc_slice_clone<T: Clone>( &self, slice: &[T], ) -> Result<BumpBox<'a, [T]>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_slice_clone.
Sourcepub fn alloc_slice_fill<T: Clone>(
&self,
len: usize,
value: T,
) -> BumpBox<'a, [T]> ⓘ
pub fn alloc_slice_fill<T: Clone>( &self, len: usize, value: T, ) -> BumpBox<'a, [T]> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_slice_fill.
Sourcepub fn try_alloc_slice_fill<T: Clone>(
&self,
len: usize,
value: T,
) -> Result<BumpBox<'a, [T]>, AllocError>
pub fn try_alloc_slice_fill<T: Clone>( &self, len: usize, value: T, ) -> Result<BumpBox<'a, [T]>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_slice_fill.
Sourcepub fn alloc_slice_fill_with<T>(
&self,
len: usize,
f: impl FnMut() -> T,
) -> BumpBox<'a, [T]> ⓘ
pub fn alloc_slice_fill_with<T>( &self, len: usize, f: impl FnMut() -> T, ) -> BumpBox<'a, [T]> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_slice_fill_with.
Sourcepub fn try_alloc_slice_fill_with<T>(
&self,
len: usize,
f: impl FnMut() -> T,
) -> Result<BumpBox<'a, [T]>, AllocError>
pub fn try_alloc_slice_fill_with<T>( &self, len: usize, f: impl FnMut() -> T, ) -> Result<BumpBox<'a, [T]>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_slice_fill_with.
Sourcepub fn alloc_str(&self, src: &str) -> BumpBox<'a, str> ⓘ
pub fn alloc_str(&self, src: &str) -> BumpBox<'a, str> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_str.
Sourcepub fn try_alloc_str(&self, src: &str) -> Result<BumpBox<'a, str>, AllocError>
pub fn try_alloc_str(&self, src: &str) -> Result<BumpBox<'a, str>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_str.
Sourcepub fn alloc_fmt(&self, args: Arguments<'_>) -> BumpBox<'a, str> ⓘ
pub fn alloc_fmt(&self, args: Arguments<'_>) -> BumpBox<'a, str> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_fmt.
Sourcepub fn try_alloc_fmt(
&self,
args: Arguments<'_>,
) -> Result<BumpBox<'a, str>, AllocError>
pub fn try_alloc_fmt( &self, args: Arguments<'_>, ) -> Result<BumpBox<'a, str>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_fmt.
Sourcepub fn alloc_fmt_mut(&mut self, args: Arguments<'_>) -> BumpBox<'a, str> ⓘ
pub fn alloc_fmt_mut(&mut self, args: Arguments<'_>) -> BumpBox<'a, str> ⓘ
Forwards to MutBumpAllocatorTypedScope::alloc_fmt_mut.
Sourcepub fn try_alloc_fmt_mut(
&mut self,
args: Arguments<'_>,
) -> Result<BumpBox<'a, str>, AllocError>
pub fn try_alloc_fmt_mut( &mut self, args: Arguments<'_>, ) -> Result<BumpBox<'a, str>, AllocError>
Forwards to MutBumpAllocatorTypedScope::try_alloc_fmt_mut.
Sourcepub fn alloc_cstr(&self, src: &CStr) -> &'a CStr
pub fn alloc_cstr(&self, src: &CStr) -> &'a CStr
Forwards to BumpAllocatorTypedScope::alloc_cstr.
Sourcepub fn try_alloc_cstr(&self, src: &CStr) -> Result<&'a CStr, AllocError>
pub fn try_alloc_cstr(&self, src: &CStr) -> Result<&'a CStr, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_cstr.
Sourcepub fn alloc_cstr_from_str(&self, src: &str) -> &'a CStr
pub fn alloc_cstr_from_str(&self, src: &str) -> &'a CStr
Forwards to BumpAllocatorTypedScope::alloc_cstr_from_str.
Sourcepub fn try_alloc_cstr_from_str(&self, src: &str) -> Result<&'a CStr, AllocError>
pub fn try_alloc_cstr_from_str(&self, src: &str) -> Result<&'a CStr, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_cstr_from_str.
Sourcepub fn alloc_cstr_fmt(&self, args: Arguments<'_>) -> &'a CStr
pub fn alloc_cstr_fmt(&self, args: Arguments<'_>) -> &'a CStr
Forwards to BumpAllocatorTypedScope::alloc_cstr_fmt.
Sourcepub fn try_alloc_cstr_fmt(
&self,
args: Arguments<'_>,
) -> Result<&'a CStr, AllocError>
pub fn try_alloc_cstr_fmt( &self, args: Arguments<'_>, ) -> Result<&'a CStr, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_cstr_fmt.
Sourcepub fn alloc_cstr_fmt_mut(&mut self, args: Arguments<'_>) -> &'a CStr
pub fn alloc_cstr_fmt_mut(&mut self, args: Arguments<'_>) -> &'a CStr
Forwards to MutBumpAllocatorTypedScope::alloc_cstr_fmt_mut.
Sourcepub fn try_alloc_cstr_fmt_mut(
&mut self,
args: Arguments<'_>,
) -> Result<&'a CStr, AllocError>
pub fn try_alloc_cstr_fmt_mut( &mut self, args: Arguments<'_>, ) -> Result<&'a CStr, AllocError>
Forwards to MutBumpAllocatorTypedScope::try_alloc_cstr_fmt_mut.
Sourcepub fn alloc_iter<T>(
&self,
iter: impl IntoIterator<Item = T>,
) -> BumpBox<'a, [T]> ⓘ
pub fn alloc_iter<T>( &self, iter: impl IntoIterator<Item = T>, ) -> BumpBox<'a, [T]> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_iter.
Sourcepub fn try_alloc_iter<T>(
&self,
iter: impl IntoIterator<Item = T>,
) -> Result<BumpBox<'a, [T]>, AllocError>
pub fn try_alloc_iter<T>( &self, iter: impl IntoIterator<Item = T>, ) -> Result<BumpBox<'a, [T]>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_iter.
Sourcepub fn alloc_iter_exact<T, I>(
&self,
iter: impl IntoIterator<Item = T, IntoIter = I>,
) -> BumpBox<'a, [T]> ⓘwhere
I: ExactSizeIterator<Item = T>,
pub fn alloc_iter_exact<T, I>(
&self,
iter: impl IntoIterator<Item = T, IntoIter = I>,
) -> BumpBox<'a, [T]> ⓘwhere
I: ExactSizeIterator<Item = T>,
Forwards to BumpAllocatorTypedScope::alloc_iter_exact.
Sourcepub 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>,
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>,
Forwards to BumpAllocatorTypedScope::try_alloc_iter_exact.
Sourcepub fn alloc_iter_mut<T>(
&mut self,
iter: impl IntoIterator<Item = T>,
) -> BumpBox<'a, [T]> ⓘ
pub fn alloc_iter_mut<T>( &mut self, iter: impl IntoIterator<Item = T>, ) -> BumpBox<'a, [T]> ⓘ
Forwards to MutBumpAllocatorTypedScope::alloc_iter_mut.
Sourcepub fn try_alloc_iter_mut<T>(
&mut self,
iter: impl IntoIterator<Item = T>,
) -> Result<BumpBox<'a, [T]>, AllocError>
pub fn try_alloc_iter_mut<T>( &mut self, iter: impl IntoIterator<Item = T>, ) -> Result<BumpBox<'a, [T]>, AllocError>
Forwards to MutBumpAllocatorTypedScope::try_alloc_iter_mut.
Sourcepub fn alloc_iter_mut_rev<T>(
&mut self,
iter: impl IntoIterator<Item = T>,
) -> BumpBox<'a, [T]> ⓘ
pub fn alloc_iter_mut_rev<T>( &mut self, iter: impl IntoIterator<Item = T>, ) -> BumpBox<'a, [T]> ⓘ
Forwards to MutBumpAllocatorTypedScope::alloc_iter_mut_rev.
Sourcepub fn try_alloc_iter_mut_rev<T>(
&mut self,
iter: impl IntoIterator<Item = T>,
) -> Result<BumpBox<'a, [T]>, AllocError>
pub fn try_alloc_iter_mut_rev<T>( &mut self, iter: impl IntoIterator<Item = T>, ) -> Result<BumpBox<'a, [T]>, AllocError>
Forwards to MutBumpAllocatorTypedScope::try_alloc_iter_mut_rev.
Sourcepub fn alloc_uninit<T>(&self) -> BumpBox<'a, MaybeUninit<T>> ⓘ
pub fn alloc_uninit<T>(&self) -> BumpBox<'a, MaybeUninit<T>> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_uninit.
Sourcepub fn try_alloc_uninit<T>(
&self,
) -> Result<BumpBox<'a, MaybeUninit<T>>, AllocError>
pub fn try_alloc_uninit<T>( &self, ) -> Result<BumpBox<'a, MaybeUninit<T>>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_uninit.
Sourcepub fn alloc_uninit_slice<T>(&self, len: usize) -> BumpBox<'a, [MaybeUninit<T>]> ⓘ
pub fn alloc_uninit_slice<T>(&self, len: usize) -> BumpBox<'a, [MaybeUninit<T>]> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_uninit_slice.
Sourcepub fn try_alloc_uninit_slice<T>(
&self,
len: usize,
) -> Result<BumpBox<'a, [MaybeUninit<T>]>, AllocError>
pub fn try_alloc_uninit_slice<T>( &self, len: usize, ) -> Result<BumpBox<'a, [MaybeUninit<T>]>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_uninit_slice.
Sourcepub fn alloc_uninit_slice_for<T>(
&self,
slice: &[T],
) -> BumpBox<'a, [MaybeUninit<T>]> ⓘ
pub fn alloc_uninit_slice_for<T>( &self, slice: &[T], ) -> BumpBox<'a, [MaybeUninit<T>]> ⓘ
Forwards to BumpAllocatorTypedScope::alloc_uninit_slice_for.
Sourcepub fn try_alloc_uninit_slice_for<T>(
&self,
slice: &[T],
) -> Result<BumpBox<'a, [MaybeUninit<T>]>, AllocError>
pub fn try_alloc_uninit_slice_for<T>( &self, slice: &[T], ) -> Result<BumpBox<'a, [MaybeUninit<T>]>, AllocError>
Forwards to BumpAllocatorTypedScope::try_alloc_uninit_slice_for.
Sourcepub fn dealloc<T: ?Sized>(&self, boxed: BumpBox<'_, T>)
pub fn dealloc<T: ?Sized>(&self, boxed: BumpBox<'_, T>)
Forwards to BumpAllocatorTyped::dealloc.
Sourcepub fn reserve(&self, additional: usize)
pub fn reserve(&self, additional: usize)
Forwards to BumpAllocatorTyped::reserve.
Sourcepub fn try_reserve(&self, additional: usize) -> Result<(), AllocError>
pub fn try_reserve(&self, additional: usize) -> Result<(), AllocError>
Forwards to BumpAllocatorTyped::try_reserve.
Sourcepub fn alloc_try_with<T, E>(
&self,
f: impl FnOnce() -> Result<T, E>,
) -> Result<BumpBox<'a, T>, E>
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);Sourcepub fn try_alloc_try_with<T, E>(
&self,
f: impl FnOnce() -> Result<T, E>,
) -> Result<Result<BumpBox<'a, T>, E>, AllocError>
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);Sourcepub fn alloc_try_with_mut<T, E>(
&mut self,
f: impl FnOnce() -> Result<T, E>,
) -> Result<BumpBox<'a, T>, E>
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);Sourcepub fn try_alloc_try_with_mut<T, E>(
&mut self,
f: impl FnOnce() -> Result<T, E>,
) -> Result<Result<BumpBox<'a, T>, E>, AllocError>
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);