pub struct GrantRegionAllocator { /* private fields */ }
Expand description

Tool for allocating additional memory regions in a process’s grant region.

This is optionally provided along with a grant so that if a capsule needs per-process dynamic allocation it can allocate additional memory.

Implementations§

source§

impl GrantRegionAllocator

source

pub fn alloc_with<T, F>(&mut self, init: F) -> Result<CustomGrant<T>, Error>
where F: FnOnce() -> T,

Allocates a new CustomGrant initialized using the given closure.

The closure will be called exactly once, and the result will be used to initialize the owned value.

This interface was chosen instead of a simple alloc(val) as it’s much more likely to optimize out all stack intermediates. This helps to prevent stack overflows when allocating large values.

Panic Safety

If init panics, the freshly allocated memory may leak.

source

pub fn alloc_n_with<T, F, const NUM_ITEMS: usize>( &mut self, init: F ) -> Result<CustomGrant<[T; NUM_ITEMS]>, Error>
where F: FnMut(usize) -> T,

Allocates a slice of n instances of a given type. Each instance is initialized using the provided function.

The provided function will be called exactly n times, and will be passed the index it’s initializing, from 0 through NUM_ITEMS - 1.

Panic Safety

If val_func panics, the freshly allocated memory and any values already written will be leaked.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> SizedTypeProperties for T

source§

const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.