SyntaxArena

Struct SyntaxArena 

Source
pub struct SyntaxArena { /* private fields */ }
Expand description

A high-performance bump allocator optimized for AST nodes.

The arena works by “bumping” a pointer within a pre-allocated chunk of memory. When a chunk is exhausted, a new one is requested from the thread-local pool or the global allocator.

Implementations§

Source§

impl SyntaxArena

Source

pub fn new(capacity: usize) -> Self

Creates a new empty arena.

Initial pointers are set to dangling. The first allocation will trigger a chunk allocation.

Source

pub fn alloc<T>(&self, value: T) -> &mut T

Allocates a value of type T in the arena and moves value into it.

§Safety

The caller must ensure that T is a POD (Plain Old Data) type. The Drop implementation for T (if any) will not be called when the arena is dropped.

§Panics

Panics if the allocation fails (OOM).

Source

pub fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> &mut [T]

Allocates a slice in the arena and copies the contents of slice into it.

This is useful for storing strings or other contiguous data in the arena.

§Safety

Same as alloc, T must be Copy (and thus POD).

Source

pub fn alloc_slice_fill_iter<T, I>(&self, count: usize, iter: I) -> &mut [T]
where I: IntoIterator<Item = T>,

Allocates a slice in the arena and fills it using an iterator.

This is more efficient than collecting into a temporary Vec and then copying, as it writes directly into the arena memory.

§Safety

The iterator must yield exactly count items. If it yields fewer, the remaining memory will be uninitialized (UB if accessed). If it yields more, the extra items are ignored. T must be POD.

Trait Implementations§

Source§

impl Default for SyntaxArena

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for SyntaxArena

Source§

fn drop(&mut self)

Drops the arena, recycling all its chunks back to the thread-local pool or freeing them.

Source§

impl Send for SyntaxArena

Source§

impl Sync for SyntaxArena

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.