pub struct ManuallyDropArena<T, Options: ArenaOptions<T> = Options> { /* private fields */ }
Expand description

Like Arena, but returns references of any lifetime, including 'static.

This lets the arena be used without being borrowed, but it comes with the tradeoff that the arena leaks memory unless the unsafe drop method is called.

Implementations

Creates a new ManuallyDropArena.

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 custom Drop impl.
  • T’s Drop 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.

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.

Returns the total number of items that have been allocated.

Checks whether the arena is empty.

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.

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.

Returns an iterator over the items in this arena.

Returns an iterator over the items in this arena.

Safety

There must be no mutable references to items (or parts of items) in this arena or instances of IterMut for this arena.

Returns a mutable iterator over the items in this arena.

Safety

There must be no references to items (or parts of items) in this arena or instances of Iter or IterMut for this arena.

Returns an owning iterator over the items in this arena.

Safety

There must be no references to items (or parts of items) in this arena or instances of Iter or IterMut for this arena.

Returns an iterator starting at the specified position.

Panics

May panic if position does not refer to a position in this arena.

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.

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.

Trait Implementations

Returns the “default value” for a type. Read more
Which kind of iterator are we turning this into?
The type of the elements being iterated over.
Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.