pub trait Arena: Allocator {
// Required methods
fn alloc<T>(&self, value: T) -> &mut T;
fn alloc_with<T>(&self, f: impl FnOnce() -> T) -> &mut T;
fn alloc_str(&self, src: &str) -> &mut str;
fn alloc_fmt(&self, arguments: Arguments<'_>) -> &mut str;
fn alloc_slice_copy<T>(&self, src: &[T]) -> &mut [T]
where T: Copy;
fn alloc_slice_clone<T>(&self, src: &[T]) -> &mut [T]
where T: Clone;
fn alloc_slice_fill_copy<T>(&self, len: usize, value: T) -> &mut [T]
where T: Copy;
fn alloc_slice_fill_clone<T>(&self, len: usize, value: &T) -> &mut [T]
where T: Clone;
fn alloc_slice_fill_with<T>(
&self,
len: usize,
f: impl FnMut(usize) -> T,
) -> &mut [T];
fn alloc_slice_fill_default<T>(&self, len: usize) -> &mut [T]
where T: Default;
fn alloc_slice_fill_iter<T>(
&self,
iter: impl IntoIterator<Item = T>,
) -> &mut [T];
}Expand description
Ergonomic, bumpalo-style allocation on top of any Allocator.
Every method returns a reference (or mutable slice) tied to the borrow of the
arena, so the allocation escapes the call and lives for the arena’s lifetime.
Implemented for every Allocator (including the three arenas and shared
references to them) via a blanket impl.
Required Methods§
Sourcefn alloc_with<T>(&self, f: impl FnOnce() -> T) -> &mut T
fn alloc_with<T>(&self, f: impl FnOnce() -> T) -> &mut T
Allocates the result of f, evaluated directly into the arena slot.
Sourcefn alloc_fmt(&self, arguments: Arguments<'_>) -> &mut str
fn alloc_fmt(&self, arguments: Arguments<'_>) -> &mut str
Formats arguments directly into the arena and returns the resulting string.
The arena-equivalent of format!, with no intermediate global allocation:
use mago_allocator::prelude::*;
let arena = LocalArena::new();
let greeting = arena.alloc_fmt(format_args!("{}-{}", "v", 2));
assert_eq!(greeting, "v-2");Sourcefn alloc_slice_copy<T>(&self, src: &[T]) -> &mut [T]where
T: Copy,
fn alloc_slice_copy<T>(&self, src: &[T]) -> &mut [T]where
T: Copy,
Copies a slice of Copy values into the arena.
Sourcefn alloc_slice_clone<T>(&self, src: &[T]) -> &mut [T]where
T: Clone,
fn alloc_slice_clone<T>(&self, src: &[T]) -> &mut [T]where
T: Clone,
Clones a slice of Clone values into the arena.
Sourcefn alloc_slice_fill_copy<T>(&self, len: usize, value: T) -> &mut [T]where
T: Copy,
fn alloc_slice_fill_copy<T>(&self, len: usize, value: T) -> &mut [T]where
T: Copy,
Allocates len copies of value.
Sourcefn alloc_slice_fill_clone<T>(&self, len: usize, value: &T) -> &mut [T]where
T: Clone,
fn alloc_slice_fill_clone<T>(&self, len: usize, value: &T) -> &mut [T]where
T: Clone,
Allocates len clones of value.
Sourcefn alloc_slice_fill_with<T>(
&self,
len: usize,
f: impl FnMut(usize) -> T,
) -> &mut [T]
fn alloc_slice_fill_with<T>( &self, len: usize, f: impl FnMut(usize) -> T, ) -> &mut [T]
Allocates len elements, each produced by f(index).
Sourcefn alloc_slice_fill_default<T>(&self, len: usize) -> &mut [T]where
T: Default,
fn alloc_slice_fill_default<T>(&self, len: usize) -> &mut [T]where
T: Default,
Allocates len default-constructed elements.
Sourcefn alloc_slice_fill_iter<T>(
&self,
iter: impl IntoIterator<Item = T>,
) -> &mut [T]
fn alloc_slice_fill_iter<T>( &self, iter: impl IntoIterator<Item = T>, ) -> &mut [T]
Collects iter into the arena and returns the resulting slice.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".