Skip to main content

BumpAllocatorTypedScopeExt

Trait BumpAllocatorTypedScopeExt 

Source
pub trait BumpAllocatorTypedScopeExt<'a>: BumpAllocatorTypedScope<'a> {
    // Provided 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 { ... }
}
Expand description

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

Provided 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::BumpAllocatorTypedScopeExt};
let bump: Bump = Bump::new();

let zero = bump.as_scope().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, zerocopy_08::BumpAllocatorTypedScopeExt};
let bump: Bump = Bump::new();

let zero = bump.as_scope().try_alloc_zeroed::<i32>()?;
assert_eq!(*zero, 0);
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::BumpAllocatorTypedScopeExt};
let bump: Bump = Bump::new();

let zeroes = bump.as_scope().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, zerocopy_08::BumpAllocatorTypedScopeExt};
let bump: Bump = Bump::new();

let zeroes = bump.as_scope().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§