fdf

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

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,

Source§

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

Source§

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

Source§

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.