pub struct Bumper<'t, ET: Default> { /* private fields */ }
Expand description

Structure intended to support bumpalo AST generations, which allows recursive AST types to be defined using references instead of smart pointers (LBox). The benefit of bump-allocated ASTs is the ability to pattern match against nested, recursive structures, e.g., Negative(Negative(x)). The lifetime 't of a Bumper should be the same as the lifetime of the parser’s input. This structure is intended to become the ‘external state’ that’s carried by the runtime parser (parser.exstate), and therefore wraps another value (exstate) of the declared externtype.

Implementations§

source§

impl<'t, T: Default> Bumper<'t, T>

source

pub fn set(&mut self, b: &'t Bump)

sets the encapsulated Bump allocator

source

pub fn is_set(&self) -> bool

tests if the allocator has been set

source

pub fn get(&self) -> &'t Bump

returns pointer to the bump allocator. Warning: this function calls unwrap and should only be called after Bumper::set has been called

source

pub fn make<S>(&self, x: S) -> &'t S

bump-allocates x and returns a reference, which will live as long as the bump allocator. Warning: this function calls unwrap and will panic if the Bumper is not set.

source

pub fn make_safe<S>(&self, x: S) -> Option<&'t S>

version of make that returns Option, but will not panic

source

pub fn alloc<S>(&self, x: S) -> Option<&'t mut S>

version of make_safe that returns a mutable reference to the allocated value

source

pub fn state(&mut self) -> &mut T

returns a mut reference to the encapsulated “state” of type ET

Trait Implementations§

source§

impl<T: Default> Default for Bumper<'_, T>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'t, ET> !RefUnwindSafe for Bumper<'t, ET>

§

impl<'t, ET> !Send for Bumper<'t, ET>

§

impl<'t, ET> !Sync for Bumper<'t, ET>

§

impl<'t, ET> Unpin for Bumper<'t, ET>
where ET: Unpin,

§

impl<'t, ET> !UnwindSafe for Bumper<'t, ET>

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>,

§

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>,

§

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.