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
impl Arena
Sourcepub unsafe fn from_raw(ptr: NonNull<fdf_arena_t>) -> Self
pub unsafe fn from_raw(ptr: NonNull<fdf_arena_t>) -> Self
Sourcepub fn contains_ptr<T: ?Sized>(&self, ptr: &T) -> bool
pub fn contains_ptr<T: ?Sized>(&self, ptr: &T) -> bool
Returns true if the allocation pointed to was made by this arena
Sourcepub fn contains<T: ?Sized>(&self, item: &ArenaBox<'_, T>) -> bool
pub fn contains<T: ?Sized>(&self, item: &ArenaBox<'_, T>) -> bool
Returns true if the allocation was made by this arena
Sourcepub fn insert_uninit<T: Sized>(&self) -> ArenaBox<'_, MaybeUninit<T>>
pub fn insert_uninit<T: Sized>(&self) -> ArenaBox<'_, MaybeUninit<T>>
Inserts a MaybeUninit
object and returns the ArenaBox
of it.
Sourcepub fn insert_uninit_slice<T: Sized>(
&self,
len: usize,
) -> ArenaBox<'_, [MaybeUninit<T>]>
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.
Sourcepub fn insert<T: Sized>(&self, obj: T) -> ArenaBox<'_, T>
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.
Sourcepub fn insert_slice<T: Sized + Clone>(&self, slice: &[T]) -> ArenaBox<'_, [T]>
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.
Sourcepub unsafe fn assume_unchecked<T: ?Sized>(
&self,
ptr: NonNull<T>,
) -> ArenaBox<'_, T>
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.
Sourcepub unsafe fn assume<T: ?Sized>(&self, ptr: NonNull<T>) -> ArenaBox<'_, T>
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
ArenaBox
ed object.
Sourcepub fn make_static<T: ?Sized>(&self, data: ArenaBox<'_, T>) -> ArenaStaticBox<T>
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.
Sourcepub fn insert_from_iter<I: IntoIterator>(
&self,
source: I,
) -> ArenaBox<'_, [I::Item]>where
I::IntoIter: ExactSizeIterator,
pub fn insert_from_iter<I: IntoIterator>(
&self,
source: I,
) -> ArenaBox<'_, [I::Item]>where
I::IntoIter: ExactSizeIterator,
Creates an ArenaBox
ed 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.
Sourcepub fn try_insert_from_iter<I, T, E>(
&self,
source: I,
) -> Result<ArenaBox<'_, [T]>, E>
pub fn try_insert_from_iter<I, T, E>( &self, source: I, ) -> Result<ArenaBox<'_, [T]>, E>
Tries to create an ArenaBox
ed 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
Sourcepub fn into_raw(self) -> NonNull<fdf_arena_t>
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§
impl Send for Arena
impl Sync for Arena
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)