Struct fixed_typed_arena::ManuallyDropArena
source · [−]pub struct ManuallyDropArena<T, const CHUNK_SIZE: usize>(_);
Expand description
Implementations
sourceimpl<T, const CHUNK_SIZE: usize> ManuallyDropArena<T, CHUNK_SIZE>
impl<T, const CHUNK_SIZE: usize> ManuallyDropArena<T, CHUNK_SIZE>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new ManuallyDropArena
.
sourcepub fn alloc<'a>(&mut self, value: T) -> &'a mut T
pub fn alloc<'a>(&mut self, value: T) -> &'a mut T
Allocates a new item in the arena and initializes it with value
.
Returns a reference to the allocated item. The reference can have any
lifetime, including 'static
, as long as T
outlives that lifetime.
sourcepub unsafe fn drop(&mut self)
pub unsafe fn drop(&mut self)
Drops the contents of the arena. The arena will leak memory when dropped unless this method is called.
Safety
You must ensure that no references to items (or parts of items) in the arena exist when calling this method, except possibly for references within the items themselves.
However, if there are references to other items (or parts of items) within the items themselves, at least one of the following must be true:
T
does not have a customDrop
impl.T
’sDrop
impl does not directly or indirectly access any data via the references to other items or parts of items. (This is essentially the requirement imposed by#[may_dangle]
.)
sourcepub unsafe fn manually_drop(&mut self)
pub unsafe fn manually_drop(&mut self)
Alias of Self::drop
. Can be used to prevent name collisions when
this arena is stored in a Deref
type:
let mut arena = Box::new(ManuallyDropArena::<u8, 8>::new());
//unsafe { arena.drop() }; // Compile error: resolves to `Drop::drop`
unsafe { arena.manually_drop() }; // Works as expected
Safety
Same requirements as Self::drop
.
Trait Implementations
Auto Trait Implementations
impl<T, const CHUNK_SIZE: usize> !RefUnwindSafe for ManuallyDropArena<T, CHUNK_SIZE>
impl<T, const CHUNK_SIZE: usize> Send for ManuallyDropArena<T, CHUNK_SIZE> where
T: Send,
impl<T, const CHUNK_SIZE: usize> !Sync for ManuallyDropArena<T, CHUNK_SIZE>
impl<T, const CHUNK_SIZE: usize> Unpin for ManuallyDropArena<T, CHUNK_SIZE> where
T: Unpin,
impl<T, const CHUNK_SIZE: usize> UnwindSafe for ManuallyDropArena<T, CHUNK_SIZE> where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more