BumpScopeExt

Trait BumpScopeExt 

Source
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§

Source

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

Allocate a zeroed object.

§Panics

Panics if the allocation fails.

§Examples
use bump_scope::{Bump, zerocopy_08::BumpScopeExt};
let mut bump: Bump = Bump::new();

bump.scoped(|bump| {
    let zero = bump.alloc_zeroed::<i32>();
    assert_eq!(*zero, 0);
});
Source

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(())
})?;
Source

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

Allocate a zeroed object slice.

§Panics

Panics if the allocation fails.

§Examples
use bump_scope::{Bump, zerocopy_08::BumpScopeExt};
let mut bump: Bump = Bump::new();

bump.scoped(|bump| {
    let zeroes = bump.alloc_zeroed_slice::<i32>(3);
    assert_eq!(*zeroes, [0; 3]);
});
Source

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.

Implementors§

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