pub struct ManuallyDropArena<T, Options: ArenaOptions<T> = Options> { /* private fields */ }
Expand description
Implementations§
source§impl<T, Options: ArenaOptions<T>> ManuallyDropArena<T, Options>
impl<T, Options: ArenaOptions<T>> ManuallyDropArena<T, Options>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new ManuallyDropArena
.
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]
.)
Additionally, there must be no instances of Iter
or IterMut
for this arena.
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
.
sourcepub fn alloc<'a>(&mut self, value: T) -> &'a mut Twhere
Options: 'a + ArenaOptions<T, Mutable = Bool<true>>,
pub fn alloc<'a>(&mut self, value: T) -> &'a mut Twhere Options: 'a + ArenaOptions<T, Mutable = Bool<true>>,
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.
This method calls handle_alloc_error
if memory allocation fails;
for a version that returns None
, see Self::try_alloc
.
sourcepub fn try_alloc<'a>(&mut self, value: T) -> Option<&'a mut T>where
Options: 'a + ArenaOptions<T, Mutable = Bool<true>>,
pub fn try_alloc<'a>(&mut self, value: T) -> Option<&'a mut T>where Options: 'a + ArenaOptions<T, Mutable = Bool<true>>,
Like Self::alloc
, but returns None
if memory allocation fails.
Allocates a new item in the arena and initializes it with value
.
Returns a shared/immutable reference to the allocated item. The
reference can have any lifetime, including 'static
, as long as T
outlives that lifetime.
This method calls handle_alloc_error
if memory allocation fails;
for a version that returns None
, see Self::try_alloc
.
Like Self::alloc_shared
, but returns None
if memory allocation
fails.
sourcepub fn iter<'a>(&self) -> Iter<'a, T, Options> ⓘwhere
Options: ArenaOptions<T, Mutable = Bool<false>>,
pub fn iter<'a>(&self) -> Iter<'a, T, Options> ⓘwhere Options: ArenaOptions<T, Mutable = Bool<false>>,
Returns an iterator over the items in this arena.
sourcepub unsafe fn iter_unchecked<'a>(&self) -> Iter<'a, T, Options> ⓘ
pub unsafe fn iter_unchecked<'a>(&self) -> Iter<'a, T, Options> ⓘ
sourcepub unsafe fn iter_mut_unchecked<'a>(&mut self) -> IterMut<'a, T, Options> ⓘ
pub unsafe fn iter_mut_unchecked<'a>(&mut self) -> IterMut<'a, T, Options> ⓘ
source§impl<T, Options> ManuallyDropArena<T, Options>where
Options: ArenaOptions<T, SupportsPositions = Bool<true>>,
impl<T, Options> ManuallyDropArena<T, Options>where Options: ArenaOptions<T, SupportsPositions = Bool<true>>,
sourcepub fn iter_at<'a>(&self, position: &Position) -> Iter<'a, T, Options> ⓘwhere
Options: ArenaOptions<T, Mutable = Bool<false>>,
pub fn iter_at<'a>(&self, position: &Position) -> Iter<'a, T, Options> ⓘwhere Options: ArenaOptions<T, Mutable = Bool<false>>,
Returns an iterator starting at the specified position.
Panics
May panic if position
does not refer to a position in this arena.
sourcepub unsafe fn iter_at_unchecked<'a>(
&self,
position: &Position
) -> Iter<'a, T, Options> ⓘ
pub unsafe fn iter_at_unchecked<'a>( &self, position: &Position ) -> Iter<'a, T, Options> ⓘ
Returns an iterator starting at the specified position.
Panics
May panic if position
does not refer to a position in this arena.
Safety
Same requirements as Self::iter_unchecked
.
sourcepub unsafe fn iter_mut_at_unchecked<'a>(
&mut self,
position: &Position
) -> IterMut<'a, T, Options> ⓘ
pub unsafe fn iter_mut_at_unchecked<'a>( &mut self, position: &Position ) -> IterMut<'a, T, Options> ⓘ
Returns a mutable iterator starting at the specified position.
Panics
May panic if position
does not refer to a position in this arena.
Safety
Same requirements as Self::iter_mut_unchecked
.