pub trait BumpScopeExt<'a>: Sealed {
// Required methods
fn alloc_zeroed<T>(&self) -> BumpBox<'a, T> ⓘ
where T: FromZeros;
fn try_alloc_zeroed<T>(&self) -> Result<BumpBox<'a, T>, AllocError>
where T: FromZeros;
fn alloc_zeroed_slice<T>(&self, len: usize) -> BumpBox<'a, [T]> ⓘ
where T: FromZeros;
fn try_alloc_zeroed_slice<T>(
&self,
len: usize,
) -> Result<BumpBox<'a, [T]>, AllocError>
where T: FromZeros;
}Available on crate feature
zerocopy-08 only.Expand description
Extension trait for BumpScope that adds the (try_)alloc_zeroed(_slice) methods.
Required Methods§
Sourcefn alloc_zeroed<T>(&self) -> BumpBox<'a, T> ⓘwhere
T: FromZeros,
fn alloc_zeroed<T>(&self) -> BumpBox<'a, T> ⓘwhere
T: FromZeros,
Sourcefn try_alloc_zeroed<T>(&self) -> Result<BumpBox<'a, T>, AllocError>where
T: FromZeros,
fn try_alloc_zeroed<T>(&self) -> Result<BumpBox<'a, T>, AllocError>where
T: FromZeros,
Allocate a zeroed object.
§Errors
Errors if the allocation fails.
§Examples
use bump_scope::{Bump, alloc::AllocError, zerocopy_08::BumpScopeExt};
let mut bump: Bump = Bump::try_new()?;
bump.scoped(|bump| -> Result<(), AllocError> {
let zero = bump.try_alloc_zeroed::<i32>()?;
assert_eq!(*zero, 0);
Ok(())
})?;Sourcefn try_alloc_zeroed_slice<T>(
&self,
len: usize,
) -> Result<BumpBox<'a, [T]>, AllocError>where
T: FromZeros,
fn try_alloc_zeroed_slice<T>(
&self,
len: usize,
) -> Result<BumpBox<'a, [T]>, AllocError>where
T: FromZeros,
Allocate a zeroed object slice.
§Errors
Errors if the allocation fails.
§Examples
use bump_scope::{Bump, alloc::AllocError, zerocopy_08::BumpScopeExt};
let mut bump: Bump = Bump::try_new()?;
bump.scoped(|bump| -> Result<(), AllocError> {
let zeroes = bump.try_alloc_zeroed_slice::<i32>(3)?;
assert_eq!(*zeroes, [0; 3]);
Ok(())
})?;Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.