pub struct DropArena<T> { /* private fields */ }Expand description
Typed drop-honouring arena. See the module-level docs.
Implementations§
Source§impl<T> DropArena<T>
impl<T> DropArena<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty arena. The first allocation triggers the
allocation of an initial chunk holding 16 T slots.
Sourcepub fn with_chunk_capacity(chunk_capacity: usize) -> Self
pub fn with_chunk_capacity(chunk_capacity: usize) -> Self
Creates an empty arena whose chunks each hold chunk_capacity
T slots.
A chunk_capacity of zero is silently clamped to 1.
§Examples
use arena_lib::DropArena;
// Tightly-sized chunks — every alloc beyond the 4th opens a new chunk.
let arena = DropArena::<u32>::with_chunk_capacity(4);
for i in 0..4 {
let _ = arena.alloc(i);
}
assert_eq!(arena.chunk_count(), 1);
let _ = arena.alloc(99);
assert_eq!(arena.chunk_count(), 2);Sourcepub fn chunk_count(&self) -> usize
pub fn chunk_count(&self) -> usize
Number of chunks currently held.
Sourcepub fn alloc(&self, value: T) -> &mut T
pub fn alloc(&self, value: T) -> &mut T
Allocates value and returns a unique reference to it.
The value is moved into a chunk; its destructor will run when the arena is dropped. Panics only if the global allocator itself fails.
§Examples
use arena_lib::DropArena;
let arena = DropArena::<String>::new();
let s = arena.alloc(String::from("owned"));
assert_eq!(s.as_str(), "owned");Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for DropArena<T>
impl<T> !RefUnwindSafe for DropArena<T>
impl<T> Send for DropArena<T>where
T: Send,
impl<T> !Sync for DropArena<T>
impl<T> Unpin for DropArena<T>where
T: Unpin,
impl<T> UnsafeUnpin for DropArena<T>
impl<T> UnwindSafe for DropArena<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more