pub struct BumpScope<'a, A = Global, const MIN_ALIGN: usize = 1, const UP: bool = true, const GUARANTEED_ALLOCATED: bool = true, const DEALLOCATES: bool = true> { /* private fields */ }
Expand description
A bump allocation scope.
A BumpScope
’s allocations are live for 'a
, which is the lifetime of its associated BumpScopeGuard(Root)
or scoped
closure.
BumpScope
has the same allocation api as Bump
.
The only thing that is missing is reset
and methods that consume the Bump
.
For a method overview and examples, have a look at the Bump
docs.
This type is provided as a parameter to the closure of Bump::scoped
, BumpScope::scoped
or created
by BumpScopeGuard::scope
and BumpScopeGuardRoot::scope
. A Bump
can also be turned into a BumpScope
using
as_scope
, as_mut_scope
or into
.
Implementations§
Source§impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
Methods for a guaranteed allocated BumpScope
.
impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
Methods for a guaranteed allocated BumpScope
.
Sourcepub fn scoped<R>(
&mut self,
f: impl FnOnce(BumpScope<'_, A, MIN_ALIGN, UP, true, DEALLOCATES>) -> R,
) -> R
pub fn scoped<R>( &mut self, f: impl FnOnce(BumpScope<'_, A, MIN_ALIGN, UP, true, DEALLOCATES>) -> R, ) -> R
Calls f
with a new child scope.
§Examples
let mut bump: Bump = Bump::new();
bump.scoped(|bump| {
bump.alloc_str("Hello, world!");
assert_eq!(bump.stats().allocated(), 13);
});
assert_eq!(bump.stats().allocated(), 0);
Sourcepub fn scoped_aligned<const NEW_MIN_ALIGN: usize, R>(
&mut self,
f: impl FnOnce(BumpScope<'_, A, NEW_MIN_ALIGN, UP, true, DEALLOCATES>) -> R,
) -> Rwhere
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
pub fn scoped_aligned<const NEW_MIN_ALIGN: usize, R>(
&mut self,
f: impl FnOnce(BumpScope<'_, A, NEW_MIN_ALIGN, UP, true, DEALLOCATES>) -> R,
) -> Rwhere
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
Calls f
with a new child scope of a new minimum alignment.
§Examples
let mut bump: Bump = Bump::new();
// bump starts off by being aligned to 16
assert!(bump.stats().current_chunk().bump_position().is_aligned_to(16));
// allocate one byte
bump.alloc(1u8);
// now the bump is only aligned to 1
// (if our `MIN_ALIGN` was higher, it would be that)
assert!(bump.stats().current_chunk().bump_position().addr().get() % 2 == 1);
assert_eq!(bump.stats().allocated(), 1);
bump.scoped_aligned::<8, ()>(|bump| {
// in here, the bump will have the specified minimum alignment of 8
assert!(bump.stats().current_chunk().bump_position().is_aligned_to(8));
assert_eq!(bump.stats().allocated(), 8);
// allocating a value with its size being a multiple of 8 will no longer have
// to align the bump pointer before allocation
bump.alloc(1u64);
assert!(bump.stats().current_chunk().bump_position().is_aligned_to(8));
assert_eq!(bump.stats().allocated(), 16);
// allocating a value smaller than the minimum alignment must align the bump pointer
// after the allocation, resulting in some wasted space
bump.alloc(1u8);
assert!(bump.stats().current_chunk().bump_position().is_aligned_to(8));
assert_eq!(bump.stats().allocated(), 24);
});
assert_eq!(bump.stats().allocated(), 1);
Sourcepub fn aligned<const NEW_MIN_ALIGN: usize, R>(
&mut self,
f: impl FnOnce(BumpScope<'a, A, NEW_MIN_ALIGN, UP, true, DEALLOCATES>) -> R,
) -> Rwhere
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
pub fn aligned<const NEW_MIN_ALIGN: usize, R>(
&mut self,
f: impl FnOnce(BumpScope<'a, A, NEW_MIN_ALIGN, UP, true, DEALLOCATES>) -> R,
) -> Rwhere
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
Calls f
with this scope but with a new minimum alignment.
§Examples
Increase the minimum alignment:
let mut bump: Bump = Bump::new();
let bump = bump.as_mut_scope();
// here we're allocating with a `MIN_ALIGN` of `1`
let foo = bump.alloc_str("foo");
assert_eq!(bump.stats().allocated(), 3);
let bar = bump.aligned::<8, _>(|bump| {
// in here the bump position has been aligned to `8`
assert_eq!(bump.stats().allocated(), 8);
assert!(bump.stats().current_chunk().bump_position().is_aligned_to(8));
// make some allocations that benefit from the higher `MIN_ALIGN` of `8`
let bar = bump.alloc(0u64);
assert_eq!(bump.stats().allocated(), 16);
// the bump position will stay aligned to `8`
bump.alloc(0u8);
assert_eq!(bump.stats().allocated(), 24);
bar
});
assert_eq!(bump.stats().allocated(), 24);
// continue making allocations with a `MIN_ALIGN` of `1`
let baz = bump.alloc_str("baz");
assert_eq!(bump.stats().allocated(), 24 + 3);
dbg!(foo, bar, baz);
Decrease the minimum alignment:
let mut bump: Bump<Global, 8> = Bump::new();
let bump = bump.as_mut_scope();
// make some allocations that benefit from the `MIN_ALIGN` of `8`
let foo = bump.alloc(0u64);
let bar = bump.aligned::<1, _>(|bump| {
// make some allocations that benefit from the lower `MIN_ALIGN` of `1`
let bar = bump.alloc(0u8);
// the bump position will not get aligned to `8` in here
assert_eq!(bump.stats().allocated(), 8 + 1);
bar
});
// after `aligned()`, the bump position will be aligned to `8` again
// to satisfy our `MIN_ALIGN`
assert!(bump.stats().current_chunk().bump_position().is_aligned_to(8));
assert_eq!(bump.stats().allocated(), 16);
// continue making allocations that benefit from the `MIN_ALIGN` of `8`
let baz = bump.alloc(0u64);
dbg!(foo, bar, baz);
Sourcepub fn scope_guard(
&mut self,
) -> BumpScopeGuard<'_, A, MIN_ALIGN, UP, DEALLOCATES>
pub fn scope_guard( &mut self, ) -> BumpScopeGuard<'_, A, MIN_ALIGN, UP, DEALLOCATES>
Creates a new BumpScopeGuard
.
This allows for creation of child scopes.
§Examples
let mut bump: Bump = Bump::new();
{
let mut guard = bump.scope_guard();
let bump = guard.scope();
bump.alloc_str("Hello, world!");
assert_eq!(bump.stats().allocated(), 13);
}
assert_eq!(bump.stats().allocated(), 0);
Source§impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, false, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
Methods for a not guaranteed allocated BumpScope
.
impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, false, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
Methods for a not guaranteed allocated BumpScope
.
Source§impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
Methods that are always available.
impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
Methods that are always available.
Sourcepub fn checkpoint(&self) -> Checkpoint
pub fn checkpoint(&self) -> Checkpoint
Creates a checkpoint of the current bump position.
The bump position can be reset to this checkpoint with reset_to
.
§Examples
let bump: Bump = Bump::new();
let checkpoint = bump.checkpoint();
{
let hello = bump.alloc_str("hello");
assert_eq!(bump.stats().allocated(), 5);
}
unsafe { bump.reset_to(checkpoint); }
assert_eq!(bump.stats().allocated(), 0);
Sourcepub unsafe fn reset_to(&self, checkpoint: Checkpoint)
pub 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.
§Safety
- the checkpoint must have been created by this bump allocator
- the bump allocator must not have been
reset
since creation of this checkpoint - there must be no references to allocations made since creation of this checkpoint
- the checkpoint must not have been created by an
!GUARANTEED_ALLOCATED
when self isGUARANTEED_ALLOCATED
§Examples
let bump: Bump = Bump::new();
let checkpoint = bump.checkpoint();
{
let hello = bump.alloc_str("hello");
assert_eq!(bump.stats().allocated(), 5);
}
unsafe { bump.reset_to(checkpoint); }
assert_eq!(bump.stats().allocated(), 0);
Sourcepub fn stats(&self) -> Stats<'a, A, UP, GUARANTEED_ALLOCATED>
pub fn stats(&self) -> Stats<'a, A, UP, GUARANTEED_ALLOCATED>
“Returns a type which provides statistics about the memory usage of the bump allocator.
Sourcepub fn into_not_guaranteed_allocated(
self,
) -> BumpScope<'a, A, MIN_ALIGN, UP, false, DEALLOCATES>
pub fn into_not_guaranteed_allocated( self, ) -> BumpScope<'a, A, MIN_ALIGN, UP, false, DEALLOCATES>
Converts this BumpScope
into a not guaranteed allocated BumpScope
.
Sourcepub fn as_not_guaranteed_allocated(
&self,
) -> &BumpScope<'a, A, MIN_ALIGN, UP, false, DEALLOCATES>
pub fn as_not_guaranteed_allocated( &self, ) -> &BumpScope<'a, A, MIN_ALIGN, UP, false, DEALLOCATES>
Borrows BumpScope
as a not guaranteed allocated BumpScope
.
Note that it’s not possible to mutably borrow as a not guaranteed allocated bump allocator. That’s because
a user could mem::swap
it with an actual unallocated bump allocator which in turn would make &mut self
unallocated.
Sourcepub unsafe fn from_raw(ptr: NonNull<()>) -> Self
pub unsafe fn from_raw(ptr: NonNull<()>) -> Self
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 withSelf::into_raw
.- This function must only be called once with this
ptr
. - The lifetime must be the original one.
- Nothing must have been allocated since then.
Sourcepub fn as_mut_aligned<const NEW_MIN_ALIGN: usize>(
&mut self,
) -> &mut BumpScope<'a, A, NEW_MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
pub fn as_mut_aligned<const NEW_MIN_ALIGN: usize>(
&mut self,
) -> &mut BumpScope<'a, A, NEW_MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
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.
Sourcepub fn as_scope(&self) -> &Self
pub fn as_scope(&self) -> &Self
Returns &self
as is. This is useful for macros that support both Bump
and BumpScope
.
Sourcepub fn as_mut_scope(&mut self) -> &mut Self
pub fn as_mut_scope(&mut self) -> &mut Self
Returns &mut self
as is. This is useful for macros that support both Bump
and BumpScope
.
Sourcepub fn into_aligned<const NEW_MIN_ALIGN: usize>(
self,
) -> BumpScope<'a, A, NEW_MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
pub fn into_aligned<const NEW_MIN_ALIGN: usize>(
self,
) -> BumpScope<'a, A, NEW_MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<NEW_MIN_ALIGN>: SupportedMinimumAlignment,
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`!!
}
Sourcepub fn into_without_dealloc(
self,
) -> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, false>
pub fn into_without_dealloc( self, ) -> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, false>
Turns off deallocation and shrinking.
Sourcepub fn as_without_dealloc(
&self,
) -> &BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, false>
pub fn as_without_dealloc( &self, ) -> &BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, false>
Turns off deallocation and shrinking.
Sourcepub fn as_mut_without_dealloc(
&mut self,
) -> &mut BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, false>
pub fn as_mut_without_dealloc( &mut self, ) -> &mut BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, false>
Turns off deallocation and shrinking.
Sourcepub fn into_with_dealloc(
self,
) -> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, true>
pub fn into_with_dealloc( self, ) -> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, true>
Turns on deallocation and shrinking.
Sourcepub fn as_with_dealloc(
&self,
) -> &BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, true>
pub fn as_with_dealloc( &self, ) -> &BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, true>
Turns on deallocation and shrinking.
Sourcepub fn as_mut_with_dealloc(
&mut self,
) -> &mut BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, true>
pub fn as_mut_with_dealloc( &mut self, ) -> &mut BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, true>
Turns on deallocation and shrinking.
Source§impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>
Methods that are always available. (but with A: Allocator
)
impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>
Methods that are always available. (but with A: Allocator
)
Sourcepub fn into_guaranteed_allocated(
self,
f: impl FnOnce() -> Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>,
) -> BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>
pub fn into_guaranteed_allocated( self, f: impl FnOnce() -> Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>, ) -> BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>
Converts this BumpScope
into a guaranteed allocated BumpScope
.
See Bump::into_guaranteed_allocated
.
§Panics
Panics if the closure panics.
Sourcepub fn try_into_guaranteed_allocated(
self,
f: impl FnOnce() -> Result<Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>,
) -> Result<BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>
pub fn try_into_guaranteed_allocated( self, f: impl FnOnce() -> Result<Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>, ) -> Result<BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>
Converts this BumpScope
into a guaranteed allocated BumpScope
.
See Bump::try_into_guaranteed_allocated
.
§Errors
Errors if the closure fails.
Sourcepub fn as_guaranteed_allocated(
&self,
f: impl FnOnce() -> Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>,
) -> &BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>
pub fn as_guaranteed_allocated( &self, f: impl FnOnce() -> Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>, ) -> &BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>
Borrows BumpScope
as a guaranteed allocated BumpScope
.
See Bump::as_guaranteed_allocated
.
§Panics
Panics if the closure panics.
Sourcepub fn try_as_guaranteed_allocated(
&self,
f: impl FnOnce() -> Result<Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>,
) -> Result<&BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>
pub fn try_as_guaranteed_allocated( &self, f: impl FnOnce() -> Result<Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>, ) -> Result<&BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>
Borrows BumpScope
as a guaranteed allocated BumpScope
.
See Bump::try_as_guaranteed_allocated
.
§Errors
Errors if the closure fails.
Sourcepub fn as_mut_guaranteed_allocated(
&mut self,
f: impl FnOnce() -> Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>,
) -> &mut BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>
pub fn as_mut_guaranteed_allocated( &mut self, f: impl FnOnce() -> Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>, ) -> &mut BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>
Mutably borrows BumpScope
as a guaranteed allocated BumpScope
.
See Bump::as_mut_guaranteed_allocated
.
§Panics
Panics if the closure panics.
Sourcepub fn try_as_mut_guaranteed_allocated(
&mut self,
f: impl FnOnce() -> Result<Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>,
) -> Result<&mut BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>
pub fn try_as_mut_guaranteed_allocated( &mut self, f: impl FnOnce() -> Result<Bump<A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>, ) -> Result<&mut BumpScope<'a, A, MIN_ALIGN, UP, true, DEALLOCATES>, AllocError>
Mutably borrows BumpScope
as a guaranteed allocated BumpScope
.
See Bump::try_as_mut_guaranteed_allocated
.
§Errors
Errors if the closure fails.
Source§impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Methods to allocate. Available as fallible or infallible.
impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Methods to allocate. Available as fallible or infallible.
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>
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> ⓘ
Allocates space for an object, then calls f
to produce the
value to be put in that place.
In some cases this could be more performant than alloc(f())
because it
permits the compiler to directly place T
in the allocated memory instead of
constructing it on the stack and copying it over.
§Panics
Panics if the allocation fails.
§Examples
let allocated = bump.alloc_with(|| 123);
assert_eq!(allocated, 123);
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>
Allocates space for an object, then calls f
to produce the
value to be put in that place.
In some cases this could be more performant than try_alloc(f())
because it
permits the compiler to directly place T
in the allocated memory instead of
constructing it on the stack and copying it over.
§Errors
Errors if the allocation fails.
§Examples
let allocated = bump.try_alloc_with(|| 123)?;
assert_eq!(allocated, 123);
Sourcepub fn alloc_default<T: Default>(&self) -> BumpBox<'a, T> ⓘ
pub fn alloc_default<T: Default>(&self) -> BumpBox<'a, T> ⓘ
Allocate an object with its default value.
This is equivalent to alloc_with(T::default)
.
§Panics
Panics if the allocation fails.
§Examples
let allocated = bump.alloc_default::<i32>();
assert_eq!(allocated, 0);
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>
Allocate an object with its default value.
This is equivalent to try_alloc_with(T::default)
.
§Errors
Errors if the allocation fails.
§Examples
let allocated = bump.try_alloc_default()?;
assert_eq!(allocated, 0);
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.Allocate an object by cloning it.
Unlike alloc(value.clone())
this method also works for dynamically-sized types.
§Panics
Panics if the allocation fails.
§Examples
Allocate a slice
, str
, CStr
, Path
:
#![feature(clone_to_uninit)]
use std::path::Path;
let cloned = bump.alloc_clone(&[1, 2, 3]);
assert_eq!(cloned, &[1, 2, 3]);
let cloned = bump.alloc_clone("foo");
assert_eq!(cloned, "foo");
let cloned = bump.alloc_clone(c"foo");
assert_eq!(cloned, c"foo");
let cloned = bump.alloc_clone(Path::new("foo"));
assert_eq!(cloned, Path::new("foo"));
Allocate a trait object:
#![feature(clone_to_uninit)]
use core::clone::CloneToUninit;
trait FnClone: Fn() -> String + CloneToUninit {}
impl<T: ?Sized + Fn() -> String + CloneToUninit> FnClone for T {}
// the closure references a local variable
let reference = &String::from("Hello,");
// and owns a string that it will have to clone
let value = String::from("world!");
let closure = move || format!("{reference} {value}");
let object: &dyn FnClone = &closure;
assert_eq!(object(), "Hello, world!");
let bump: Bump = Bump::new();
let object_clone = bump.alloc_clone(object);
assert_eq!(object_clone(), "Hello, world!");
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.Allocate an object by cloning it.
Unlike alloc(value.clone())
this method also works for dynamically-sized types.
§Errors
Errors if the allocation fails.
§Examples
Allocate a slice
, str
, CStr
, Path
:
#![feature(clone_to_uninit)]
use std::path::Path;
let cloned = bump.try_alloc_clone(&[1, 2, 3])?;
assert_eq!(cloned, &[1, 2, 3]);
let cloned = bump.try_alloc_clone("foo")?;
assert_eq!(cloned, "foo");
let cloned = bump.try_alloc_clone(c"foo")?;
assert_eq!(cloned, c"foo");
let cloned = bump.try_alloc_clone(Path::new("foo"))?;
assert_eq!(cloned, Path::new("foo"));
Allocate a trait object:
#![feature(clone_to_uninit)]
use core::clone::CloneToUninit;
trait FnClone: Fn() -> String + CloneToUninit {}
impl<T: ?Sized + Fn() -> String + CloneToUninit> FnClone for T {}
// the closure references a local variable
let reference = &String::from("Hello,");
// and owns a string that it will have to clone
let value = String::from("world!");
let closure = move || format!("{reference} {value}");
let object: &dyn FnClone = &closure;
assert_eq!(object(), "Hello, world!");
let bump: Bump = Bump::try_new()?;
let object_clone = bump.try_alloc_clone(object)?;
assert_eq!(object_clone(), "Hello, world!");
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]> ⓘ
Allocate a slice and fill it by moving elements from an existing slice.
§Panics
Panics if the allocation fails.
§Examples
// by value
let a = bump.alloc_slice_move([1, 2]);
let b = bump.alloc_slice_move(vec![3, 4]);
let c = bump.alloc_slice_move(bump.alloc_iter(5..=6));
// by mutable reference
let mut other = vec![7, 8];
let d = bump.alloc_slice_move(&mut other);
assert!(other.is_empty());
assert_eq!(a, [1, 2]);
assert_eq!(b, [3, 4]);
assert_eq!(c, [5, 6]);
assert_eq!(d, [7, 8]);
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>
Allocate a slice and fill it by moving elements from an existing slice.
§Errors
Errors if the allocation fails.
§Examples
// by value
let a = bump.try_alloc_slice_move([1, 2])?;
let b = bump.try_alloc_slice_move(vec![3, 4])?;
let c = bump.try_alloc_slice_move(bump.alloc_iter(5..=6))?;
// by mutable reference
let mut other = vec![7, 8];
let d = bump.try_alloc_slice_move(&mut other)?;
assert!(other.is_empty());
assert_eq!(a, [1, 2]);
assert_eq!(b, [3, 4]);
assert_eq!(c, [5, 6]);
assert_eq!(d, [7, 8]);
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>
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>
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>
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]> ⓘ
Allocates a slice by fill it with elements returned by calling a closure repeatedly.
This method uses a closure to create new values. If you’d rather
Clone
a given value, use alloc_slice_fill
. If you want to use the Default
trait to generate values, you can pass Default::default
as the
argument.
§Panics
Panics if the allocation fails.
§Examples
let allocated = bump.alloc_slice_fill_with::<i32>(3, Default::default);
assert_eq!(allocated, [0, 0, 0]);
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>
Allocates a slice by fill it with elements returned by calling a closure repeatedly.
This method uses a closure to create new values. If you’d rather
Clone
a given value, use try_alloc_slice_fill
. If you want to use the Default
trait to generate values, you can pass Default::default
as the
argument.
§Errors
Errors if the allocation fails.
§Examples
let allocated = bump.try_alloc_slice_fill_with::<i32>(3, Default::default)?;
assert_eq!(allocated, [0, 0, 0]);
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>
Sourcepub fn alloc_fmt(&self, args: Arguments<'_>) -> BumpBox<'a, str> ⓘ
pub fn alloc_fmt(&self, args: Arguments<'_>) -> BumpBox<'a, str> ⓘ
Allocate a str
from format arguments.
If you have a &mut self
you can use alloc_fmt_mut
instead for better performance.
§Panics
Panics if the allocation fails.
This technically also panics if the fmt()
implementation returned an Error,
but since fmt()
implementors should only error when writing to the stream fails,
that should be equivalent to an allocation failure.
§Examples
let one = 1;
let two = 2;
let string = bump.alloc_fmt(format_args!("{one} + {two} = {}", one + two));
assert_eq!(string, "1 + 2 = 3");
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>
Allocate a str
from format arguments.
If you have a &mut self
you can use try_alloc_fmt_mut
instead for better performance.
§Errors
Errors if the allocation fails.
This technically also errors if the fmt()
implementation returned an Error,
but since fmt()
implementors should only error when writing to the stream fails,
that should be equivalent to an allocation failure.
§Examples
let one = 1;
let two = 2;
let string = bump.try_alloc_fmt(format_args!("{one} + {two} = {}", one + two))?;
assert_eq!(string, "1 + 2 = 3");
Sourcepub fn alloc_fmt_mut(&mut self, args: Arguments<'_>) -> BumpBox<'a, str> ⓘ
pub fn alloc_fmt_mut(&mut self, args: Arguments<'_>) -> BumpBox<'a, str> ⓘ
Allocate a str
from format arguments.
This function is designed as a performance improvement over alloc_fmt
.
By taking self
as &mut
, it can use the entire remaining chunk space as the capacity
for the temporary string buffer used for the allocation. As a result, that string buffer rarely needs to grow.
§Panics
Panics if the allocation fails.
This technically also panics if the fmt()
implementation returned an Error,
but since fmt()
implementors should only error when writing to the stream fails,
that should be equivalent to an allocation failure.
§Examples
let one = 1;
let two = 2;
let string = bump.alloc_fmt_mut(format_args!("{one} + {two} = {}", one + two));
assert_eq!(string, "1 + 2 = 3");
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>
Allocate a str
from format arguments.
This function is designed as a performance improvement over try_alloc_fmt
.
By taking self
as &mut
, it can use the entire remaining chunk space as the capacity
for the temporary string buffer used for the allocation. As a result, that string buffer rarely needs to grow.
§Errors
Errors if the allocation fails.
This technically also errors if the fmt()
implementation returned an Error,
but since fmt()
implementors should only error when writing to the stream fails,
that should be equivalent to an allocation failure.
§Examples
let one = 1;
let two = 2;
let string = bump.try_alloc_fmt_mut(format_args!("{one} + {two} = {}", one + two))?;
assert_eq!(string, "1 + 2 = 3");
Sourcepub fn alloc_cstr(&self, src: &CStr) -> &'a CStr
pub fn alloc_cstr(&self, src: &CStr) -> &'a 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>
Sourcepub fn alloc_cstr_from_str(&self, src: &str) -> &'a CStr
pub fn alloc_cstr_from_str(&self, src: &str) -> &'a CStr
Allocate a CStr
from a str
.
If src
contains a '\0'
then the CStr
will stop at the first '\0'
.
§Panics
Panics if the allocation fails.
§Examples
let allocated = bump.alloc_cstr_from_str("Hello, world!");
assert_eq!(allocated, c"Hello, world!");
let allocated = bump.alloc_cstr_from_str("abc\0def");
assert_eq!(allocated, c"abc");
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>
Allocate a CStr
from a str
.
If src
contains a '\0'
then the CStr
will stop at the first '\0'
.
§Errors
Errors if the allocation fails.
§Examples
let allocated = bump.try_alloc_cstr_from_str("Hello, world!")?;
assert_eq!(allocated, c"Hello, world!");
let allocated = bump.try_alloc_cstr_from_str("abc\0def")?;
assert_eq!(allocated, c"abc");
Sourcepub fn alloc_cstr_fmt(&self, args: Arguments<'_>) -> &'a CStr
pub fn alloc_cstr_fmt(&self, args: Arguments<'_>) -> &'a CStr
Allocate a CStr
from format arguments.
If the string contains a '\0'
then the CStr
will stop at the first '\0'
.
If you have a &mut self
you can use alloc_cstr_fmt_mut
instead for better performance.
§Panics
Panics if the allocation fails.
This technically also panics if the fmt()
implementation returned an Error,
but since fmt()
implementors should only error when writing to the stream fails,
that should be equivalent to an allocation failure.
§Examples
let one = 1;
let two = 2;
let string = bump.alloc_cstr_fmt(format_args!("{one} + {two} = {}", one + two));
assert_eq!(string, c"1 + 2 = 3");
let one = bump.alloc_cstr_fmt(format_args!("{one}\0{two}"));
assert_eq!(one, c"1");
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>
Allocate a CStr
from format arguments.
If the string contains a '\0'
then the CStr
will stop at the first '\0'
.
If you have a &mut self
you can use try_alloc_cstr_fmt_mut
instead for better performance.
§Errors
Errors if the allocation fails.
This technically also errors if the fmt()
implementation returned an Error,
but since fmt()
implementors should only error when writing to the stream fails,
that should be equivalent to an allocation failure.
§Examples
let one = 1;
let two = 2;
let string = bump.try_alloc_cstr_fmt(format_args!("{one} + {two} = {}", one + two))?;
assert_eq!(string, c"1 + 2 = 3");
let one = bump.try_alloc_cstr_fmt(format_args!("{one}\0{two}"))?;
assert_eq!(one, c"1");
Sourcepub fn alloc_cstr_fmt_mut(&mut self, args: Arguments<'_>) -> &'a CStr
pub fn alloc_cstr_fmt_mut(&mut self, args: Arguments<'_>) -> &'a CStr
Allocate a CStr
from format arguments.
If the string contains a '\0'
then the CStr
will stop at the first '\0'
.
This function is designed as a performance improvement over alloc_cstr_fmt
.
By taking self
as &mut
, it can use the entire remaining chunk space as the capacity
for the temporary string buffer used for the allocation. As a result, that string buffer rarely needs to grow.
§Panics
Panics if the allocation fails.
This technically also panics if the fmt()
implementation returned an Error,
but since fmt()
implementors should only error when writing to the stream fails,
that should be equivalent to an allocation failure.
§Examples
let one = 1;
let two = 2;
let string = bump.alloc_cstr_fmt_mut(format_args!("{one} + {two} = {}", one + two));
assert_eq!(string, c"1 + 2 = 3");
let one = bump.alloc_cstr_fmt_mut(format_args!("{one}\0{two}"));
assert_eq!(one, c"1");
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>
Allocate a CStr
from format arguments.
If the string contains a '\0'
then the CStr
will stop at the first '\0'
.
This function is designed as a performance improvement over try_alloc_cstr_fmt
.
By taking self
as &mut
, it can use the entire remaining chunk space as the capacity
for the temporary string buffer used for the allocation. As a result, that string buffer rarely needs to grow.
§Errors
Errors if the allocation fails.
This technically also errors if the fmt()
implementation returned an Error,
but since fmt()
implementors should only error when writing to the stream fails,
that should be equivalent to an allocation failure.
§Examples
let one = 1;
let two = 2;
let string = bump.try_alloc_cstr_fmt_mut(format_args!("{one} + {two} = {}", one + two))?;
assert_eq!(string, c"1 + 2 = 3");
let one = bump.try_alloc_cstr_fmt_mut(format_args!("{one}\0{two}"))?;
assert_eq!(one, c"1");
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]> ⓘ
Allocate elements of an iterator into a slice.
If you have an impl ExactSizeIterator
then you can use alloc_iter_exact
instead for better performance.
If iter
is not an ExactSizeIterator
but you have a &mut self
you can still get somewhat better performance by using alloc_iter_mut
.
§Panics
Panics if the allocation fails.
§Examples
let slice = bump.alloc_iter([1, 2, 3]);
assert_eq!(slice, [1, 2, 3]);
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>
Allocate elements of an iterator into a slice.
If you have an impl ExactSizeIterator
then you can use try_alloc_iter_exact
instead for better performance.
If iter
is not an ExactSizeIterator
but you have a &mut self
you can still get somewhat better performance by using try_alloc_iter_mut
.
§Errors
Errors if the allocation fails.
§Examples
let slice = bump.try_alloc_iter([1, 2, 3])?;
assert_eq!(slice, [1, 2, 3]);
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>,
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>,
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]> ⓘ
Allocate elements of an iterator into a slice.
This function is designed as a performance improvement over alloc_iter
.
By taking self
as &mut
, it can use the entire remaining chunk space as the capacity
for the temporary vector used for the allocation. As a result, that vector rarely needs to grow.
When bumping downwards, prefer alloc_iter_mut_rev
instead.
§Panics
Panics if the allocation fails.
§Examples
let slice = bump.alloc_iter_mut([1, 2, 3]);
assert_eq!(slice, [1, 2, 3]);
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>
Allocate elements of an iterator into a slice.
This function is designed as a performance improvement over try_alloc_iter
.
By taking self
as &mut
, it can use the entire remaining chunk space as the capacity
for the temporary vector used for the allocation. As a result, that vector rarely needs to grow.
When bumping downwards, prefer alloc_iter_mut_rev
instead.
§Errors
Errors if the allocation fails.
§Examples
let slice = bump.try_alloc_iter_mut([1, 2, 3])?;
assert_eq!(slice, [1, 2, 3]);
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]> ⓘ
Allocate elements of an iterator into a slice in reverse order.
Compared to alloc_iter_mut
this function is more performant
for downwards bumping allocators as the allocation for the vector can be shrunk in place
without any ptr::copy
.
The reverse is true when upwards allocating. In that case it’s better to use alloc_iter_mut
to prevent
the ptr::copy
.
§Panics
Panics if the allocation fails.
§Examples
let slice = bump.alloc_iter_mut_rev([1, 2, 3]);
assert_eq!(slice, [3, 2, 1]);
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>
Allocate elements of an iterator into a slice in reverse order.
Compared to try_alloc_iter_mut
this function is more performant
for downwards bumping allocators as the allocation for the vector can be shrunk in place
without any ptr::copy
.
The reverse is true when upwards allocating. In that case it’s better to use try_alloc_iter_mut
to prevent
the ptr::copy
.
§Errors
Errors if the allocation fails.
§Examples
let slice = bump.try_alloc_iter_mut_rev([1, 2, 3])?;
assert_eq!(slice, [3, 2, 1]);
Sourcepub fn alloc_uninit<T>(&self) -> BumpBox<'a, MaybeUninit<T>> ⓘ
pub fn alloc_uninit<T>(&self) -> BumpBox<'a, MaybeUninit<T>> ⓘ
Allocate an unitialized object.
You can safely initialize the object with init
or unsafely with assume_init
.
§Panics
Panics if the allocation fails.
§Examples
Safely:
let uninit = bump.alloc_uninit();
let five = uninit.init(5);
assert_eq!(*five, 5)
Unsafely:
let mut uninit = bump.alloc_uninit();
let five = unsafe {
uninit.write(5);
uninit.assume_init()
};
assert_eq!(*five, 5)
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>
Allocate an unitialized object.
You can safely initialize the object with init
or unsafely with assume_init
.
§Errors
Errors if the allocation fails.
§Examples
Safely:
let uninit = bump.try_alloc_uninit()?;
let five = uninit.init(5);
assert_eq!(*five, 5);
Unsafely:
let mut uninit = bump.try_alloc_uninit()?;
let five = unsafe {
uninit.write(5);
uninit.assume_init()
};
assert_eq!(*five, 5);
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>]> ⓘ
Allocate an unitialized object slice.
You can safely initialize the object with
init_fill
,
init_fill_with
,
init_copy
,
init_clone
,
init_zeroed
or unsafely with
assume_init
.
§Panics
Panics if the allocation fails.
§Examples
Safely:
let uninit = bump.alloc_uninit_slice(3);
let values = uninit.init_copy(&[1, 2, 3]);
assert_eq!(values, [1, 2, 3])
Unsafely:
let mut uninit = bump.alloc_uninit_slice(3);
let values = unsafe {
uninit[0].write(1);
uninit[1].write(2);
uninit[2].write(3);
uninit.assume_init()
};
assert_eq!(values, [1, 2, 3]);
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>
Allocate an unitialized object slice.
You can safely initialize the object with
init_fill
,
init_fill_with
,
init_copy
,
init_clone
,
init_zeroed
or unsafely with
assume_init
.
§Errors
Errors if the allocation fails.
§Examples
Safely:
let uninit = bump.try_alloc_uninit_slice(3)?;
let values = uninit.init_copy(&[1, 2, 3]);
assert_eq!(values, [1, 2, 3]);
Unsafely:
let mut uninit = bump.try_alloc_uninit_slice(3)?;
let values = unsafe {
uninit[0].write(1);
uninit[1].write(2);
uninit[2].write(3);
uninit.assume_init()
};
assert_eq!(values, [1, 2, 3]);
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>]> ⓘ
Allocate an unitialized object slice.
You can safely initialize the object with
init_fill
,
init_fill_with
,
init_copy
,
init_clone
,
init_zeroed
or unsafely with
assume_init
.
This is just like alloc_uninit_slice
but uses a slice
to provide the len
.
This avoids a check for a valid layout. The elements of slice
are irrelevant.
§Panics
Panics if the allocation fails.
§Examples
let slice = &[1, 2, 3];
let uninit_slice = bump.alloc_uninit_slice_for(slice);
assert_eq!(uninit_slice.len(), 3);
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>
Allocate an unitialized object slice.
You can safely initialize the object with
init_fill
,
init_fill_with
,
init_copy
,
init_clone
,
init_zeroed
or unsafely with
assume_init
.
This is just like try_alloc_uninit_slice
but uses a slice
to provide the len
.
This avoids a check for a valid layout. The elements of slice
are irrelevant.
§Errors
Errors if the allocation fails.
§Examples
let slice = &[1, 2, 3];
let uninit_slice = bump.try_alloc_uninit_slice_for(slice)?;
assert_eq!(uninit_slice.len(), 3);
Sourcepub fn alloc_layout(&self, layout: Layout) -> NonNull<u8>
pub fn alloc_layout(&self, layout: Layout) -> NonNull<u8>
Sourcepub fn try_alloc_layout(
&self,
layout: Layout,
) -> Result<NonNull<u8>, AllocError>
pub fn try_alloc_layout( &self, layout: Layout, ) -> Result<NonNull<u8>, AllocError>
Sourcepub fn dealloc<T: ?Sized>(&self, boxed: BumpBox<'_, T>)
pub fn dealloc<T: ?Sized>(&self, boxed: BumpBox<'_, T>)
Drops an allocated value and attempts to free its memory.
The memory can only be freed if this is the last allocation.
§Examples
let boxed = bump.alloc(3i32);
assert_eq!(bump.stats().allocated(), 4);
bump.dealloc(boxed);
assert_eq!(bump.stats().allocated(), 0);
Sourcepub fn reserve_bytes(&self, additional: usize)
pub fn reserve_bytes(&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_bytes
, self.stats().remaining()
will be greater than or equal to
additional
. Does nothing if the capacity is already sufficient.
Note that these additional bytes are not necessarily in one contiguous region but might be spread out among many chunks.
§Panics
Panics if the allocation fails.
§Examples
let bump: Bump = Bump::new();
assert!(bump.stats().capacity() < 4096);
bump.reserve_bytes(4096);
assert!(bump.stats().capacity() >= 4096);
Sourcepub fn try_reserve_bytes(&self, additional: usize) -> Result<(), AllocError>
pub fn try_reserve_bytes(&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_bytes
, self.stats().remaining()
will be greater than or equal to
additional
. Does nothing if the capacity is already sufficient.
§Errors
Errors if the allocation fails.
§Examples
let bump: Bump = Bump::try_new()?;
assert!(bump.stats().capacity() < 4096);
bump.try_reserve_bytes(4096)?;
assert!(bump.stats().capacity() >= 4096);
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);
Trait Implementations§
Source§impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for &mut BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Available on crate feature nightly-allocator-api
only.
impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for &mut BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
nightly-allocator-api
only.Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
allocator_api
)ptr
. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)grow
, but also ensures that the new contents are set to zero before being
returned. Read moreSource§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)Source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)allocate
, but also ensures that the returned memory is zero-initialized. Read moreSource§impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for &mut BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Available on crate feature allocator-api2-03
only.
impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for &mut BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
allocator-api2-03
only.Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
ptr
. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
grow
, but also ensures that the new contents are set to zero before being
returned. Read moreSource§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocate
, but also ensures that the returned memory is zero-initialized. Read moreSource§impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
ptr
. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
grow
, but also ensures that the new contents are set to zero before being
returned. Read moreSource§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocate
, but also ensures that the returned memory is zero-initialized. Read moreSource§impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Available on crate feature nightly-allocator-api
only.
impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
nightly-allocator-api
only.Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
allocator_api
)ptr
. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)grow
, but also ensures that the new contents are set to zero before being
returned. Read moreSource§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)Source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)allocate
, but also ensures that the returned memory is zero-initialized. Read moreSource§impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Available on crate feature allocator-api2-03
only.
impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> Allocator for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
allocator-api2-03
only.Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
ptr
. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
grow
, but also ensures that the new contents are set to zero before being
returned. Read moreSource§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocate
, but also ensures that the returned memory is zero-initialized. Read moreSource§impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpAllocator for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpAllocator for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Source§fn any_stats(&self) -> AnyStats<'_>
fn any_stats(&self) -> AnyStats<'_>
Source§fn checkpoint(&self) -> Checkpoint
fn checkpoint(&self) -> Checkpoint
Source§unsafe fn reset_to(&self, checkpoint: Checkpoint)
unsafe fn reset_to(&self, checkpoint: Checkpoint)
Source§fn prepare_allocation(
&self,
layout: Layout,
) -> Result<Range<NonNull<u8>>, AllocError>
fn prepare_allocation( &self, layout: Layout, ) -> Result<Range<NonNull<u8>>, AllocError>
layout.size()
. Read moreSource§impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpAllocatorExt for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
impl<A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpAllocatorExt for BumpScope<'_, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Source§type Stats<'b> = Stats<'b, A, UP, GUARANTEED_ALLOCATED>
where
Self: 'b
type Stats<'b> = Stats<'b, A, UP, GUARANTEED_ALLOCATED> where Self: 'b
Source§fn stats(&self) -> Self::Stats<'_>
fn stats(&self) -> Self::Stats<'_>
Source§fn try_allocate_layout(&self, layout: Layout) -> Result<NonNull<u8>, AllocError>
fn try_allocate_layout(&self, layout: Layout) -> Result<NonNull<u8>, AllocError>
Source§fn try_allocate_sized<T>(&self) -> Result<NonNull<T>, AllocError>
fn try_allocate_sized<T>(&self) -> Result<NonNull<T>, AllocError>
Source§fn allocate_slice<T>(&self, len: usize) -> NonNull<T>
fn allocate_slice<T>(&self, len: usize) -> NonNull<T>
Source§fn try_allocate_slice<T>(&self, len: usize) -> Result<NonNull<T>, AllocError>
fn try_allocate_slice<T>(&self, len: usize) -> Result<NonNull<T>, AllocError>
Source§unsafe fn shrink_slice<T>(
&self,
ptr: NonNull<T>,
old_len: usize,
new_len: usize,
) -> Option<NonNull<T>>
unsafe fn shrink_slice<T>( &self, ptr: NonNull<T>, old_len: usize, new_len: usize, ) -> Option<NonNull<T>>
Source§fn prepare_slice_allocation<T>(&self, len: usize) -> NonNull<[T]>
fn prepare_slice_allocation<T>(&self, len: usize) -> NonNull<[T]>
prepare_allocation
. Read moreSource§fn try_prepare_slice_allocation<T>(
&self,
len: usize,
) -> Result<NonNull<[T]>, AllocError>
fn try_prepare_slice_allocation<T>( &self, len: usize, ) -> Result<NonNull<[T]>, AllocError>
prepare_allocation
. Read moreSource§unsafe fn allocate_prepared_slice<T>(
&self,
ptr: NonNull<T>,
len: usize,
cap: usize,
) -> NonNull<[T]>
unsafe fn allocate_prepared_slice<T>( &self, ptr: NonNull<T>, len: usize, cap: usize, ) -> NonNull<[T]>
allocate_prepared
. Read moreSource§unsafe fn allocate_prepared_slice_rev<T>(
&self,
ptr: NonNull<T>,
len: usize,
cap: usize,
) -> NonNull<[T]>
unsafe fn allocate_prepared_slice_rev<T>( &self, ptr: NonNull<T>, len: usize, cap: usize, ) -> NonNull<[T]>
allocate_prepared_rev
. Read moreSource§impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScopeExt<'a> for BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Available on crate feature bytemuck
only.
impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScopeExt<'a> for BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
bytemuck
only.Source§fn alloc_zeroed<T>(&self) -> BumpBox<'a, T> ⓘwhere
T: Zeroable,
fn alloc_zeroed<T>(&self) -> BumpBox<'a, T> ⓘwhere
T: Zeroable,
Source§fn try_alloc_zeroed<T>(&self) -> Result<BumpBox<'a, T>, AllocError>where
T: Zeroable,
fn try_alloc_zeroed<T>(&self) -> Result<BumpBox<'a, T>, AllocError>where
T: Zeroable,
Source§fn alloc_zeroed_slice<T>(&self, len: usize) -> BumpBox<'a, [T]> ⓘwhere
T: Zeroable,
fn alloc_zeroed_slice<T>(&self, len: usize) -> BumpBox<'a, [T]> ⓘwhere
T: Zeroable,
Source§fn try_alloc_zeroed_slice<T>(
&self,
len: usize,
) -> Result<BumpBox<'a, [T]>, AllocError>where
T: Zeroable,
fn try_alloc_zeroed_slice<T>(
&self,
len: usize,
) -> Result<BumpBox<'a, [T]>, AllocError>where
T: Zeroable,
Source§impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScopeExt<'a> for BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
Available on crate feature zerocopy-08
only.
impl<'a, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpScopeExt<'a> for BumpScope<'a, A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>where
MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
A: BaseAllocator<GUARANTEED_ALLOCATED>,
zerocopy-08
only.