BumpExt

Trait BumpExt 

Source
pub trait BumpExt: Sealed {
    // Required methods
    fn alloc_zeroed<T>(&self) -> BumpBox<'_, T> 
       where T: FromZeros;
    fn try_alloc_zeroed<T>(&self) -> Result<BumpBox<'_, T>, AllocError>
       where T: FromZeros;
    fn alloc_zeroed_slice<T>(&self, len: usize) -> BumpBox<'_, [T]> 
       where T: FromZeros;
    fn try_alloc_zeroed_slice<T>(
        &self,
        len: usize,
    ) -> Result<BumpBox<'_, [T]>, AllocError>
       where T: FromZeros;
}
Available on crate feature zerocopy-08 only.
Expand description

Extension trait for Bump that adds the (try_)alloc_zeroed(_slice) methods.

Required Methods§

Source

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

Allocate a zeroed object.

§Panics

Panics if the allocation fails.

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

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

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

Allocate a zeroed object.

§Errors

Errors if the allocation fails.

§Examples
use bump_scope::{Bump, zerocopy_08::BumpExt};
let bump: Bump = Bump::try_new()?;

let zero = bump.try_alloc_zeroed::<i32>()?;
assert_eq!(*zero, 0);
Source

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

Allocate a zeroed object slice.

§Panics

Panics if the allocation fails.

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

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<'_, [T]>, AllocError>
where T: FromZeros,

Allocate a zeroed object slice.

§Errors

Errors if the allocation fails.

§Examples
use bump_scope::{Bump, zerocopy_08::BumpExt};
let bump: Bump = Bump::try_new()?;

let zeroes = bump.try_alloc_zeroed_slice::<i32>(3)?;
assert_eq!(*zeroes, [0; 3]);

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, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool, const DEALLOCATES: bool> BumpExt for Bump<A, MIN_ALIGN, UP, GUARANTEED_ALLOCATED, DEALLOCATES>
where MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment, A: BaseAllocator<GUARANTEED_ALLOCATED>,