Struct fdf::Arena

source ·
pub struct Arena(/* private fields */);
Expand description

Implements a memory arena allocator to be used with the Fuchsia Driver Runtime when sending and receiving from channels.

Implementations§

source§

impl Arena

source

pub fn new() -> Result<Self, Status>

Allocates a new arena for use with the driver runtime

source

pub unsafe fn from_raw(ptr: NonNull<fdf_arena_t>) -> Self

Creates an arena from a raw pointer to the arena object.

§Safety

The caller is responsible for ensuring that only one Arena is constructed from this pointer, and that is has not previously been freed.

source

pub fn contains_ptr<T: ?Sized>(&self, ptr: &T) -> bool

Returns true if the allocation pointed to was made by this arena

source

pub fn contains<T: ?Sized>(&self, item: &ArenaBox<'_, T>) -> bool

Returns true if the allocation was made by this arena

source

pub fn insert_uninit<T: Sized>(&self) -> ArenaBox<'_, MaybeUninit<T>>

Inserts a MaybeUninit object and returns the ArenaBox of it.

source

pub fn insert_uninit_slice<T: Sized>( &self, len: usize, ) -> ArenaBox<'_, [MaybeUninit<T>]>

Inserts a slice of MaybeUninit objects of len len

§Panics

Panics if an array [T; n] is too large to be allocated.

source

pub fn insert<T: Sized>(&self, obj: T) -> ArenaBox<'_, T>

Moves obj of type T into the arena and returns an ArenaBox containing the moved value.

source

pub fn insert_boxed_slice<T: Sized>(&self, slice: Box<[T]>) -> ArenaBox<'_, [T]>

Moves a Boxed slice into the arena and returns an ArenaBox containing the moved value.

source

pub fn insert_slice<T: Sized + Clone>(&self, slice: &[T]) -> ArenaBox<'_, [T]>

Copies the slice into the arena and returns an ArenaBox containing the copied values.

source

pub fn insert_default_slice<T: Sized + Default>( &self, len: usize, ) -> ArenaBox<'_, [T]>

Inserts a slice of Default-initialized objects of type T to the arena and returns an ArenaBox of it.

§Panics

Panics if an array [T; n] is too large to be allocated.

source

pub unsafe fn assume_unchecked<T: ?Sized>( &self, ptr: NonNull<T>, ) -> ArenaBox<'_, T>

Returns an ArenaBox for the pointed to object, assuming that it is part of this arena.

§Safety

This does not verify that the pointer came from this arena, so the caller is responsible for verifying that.

source

pub unsafe fn assume<T: ?Sized>(&self, ptr: NonNull<T>) -> ArenaBox<'_, T>

Returns an ArenaBox for the pointed to object, verifying that it is a part of this arena in the process.

§Panics

This function panics if the given pointer is not in this Arena.

§Safety

The caller is responsible for ensuring that only one ArenaBox is constructed for a given pointer, and that the pointer originated from an ArenaBox<T> or a direct allocation with the arena through fdf_arena_allocate, and is:

  • initialized to a value of T.
  • properly aligned for T.
  • pointing to the beginning of the object, and not to a subfield of another ArenaBoxed object.
source

pub fn make_rc<T: ?Sized>(&self, data: ArenaBox<'_, T>) -> ArenaRc<T>

Moves the given ArenaBox into an ArenaRc with an owned reference to this Arena, allowing for it to be used in 'static contexts.

§Panics

Panics if the given ArenaBox is not allocated from this arena.

source

pub fn make_static<T: ?Sized>(&self, data: ArenaBox<'_, T>) -> ArenaStaticBox<T>

Moves the given ArenaBox into an ArenaStaticBox with an owned reference to this Arena, allowing for it to be used in 'static contexts.

§Panics

Panics if the given ArenaBox is not allocated from this arena.

source

pub fn insert_from_iter<I: IntoIterator>( &self, source: I, ) -> ArenaBox<'_, [I::Item]>

Creates an ArenaBoxed slice from an iterator implementing ExactSizeIterator. Note that if ExactSizeIterator::len returns an incorrect value, the returned ArenaBox will be no more than the length returned, and may be less.

source

pub fn try_insert_from_iter<I, T, E>( &self, source: I, ) -> Result<ArenaBox<'_, [T]>, E>
where I: IntoIterator<Item = Result<T, E>>, I::IntoIter: ExactSizeIterator,

Tries to create an ArenaBoxed slice from an iterator implementing ExactSizeIterator. Note that if ExactSizeIterator::len returns an incorrect value, the returned ArenaBox will be no more than the length returned, and may be less.

If any item returned by the iterator returns an Err() result, results so far are discarded

source

pub fn into_raw(self) -> NonNull<fdf_arena_t>

Transforms this Arena into an fdf_arena_t without dropping the reference.

If the caller drops the returned fdf_arena_t, the memory allocated by the arena will never be freed.

Trait Implementations§

source§

impl Clone for Arena

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Arena

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Arena

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for Arena

source§

impl Sync for Arena

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.