Struct rustlr::generic_absyn::Bumper
source · 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>
impl<'t, T: Default> Bumper<'t, T>
sourcepub fn get(&self) -> &'t Bump
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
sourcepub fn make<S>(&self, x: S) -> &'t S
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.
sourcepub fn make_safe<S>(&self, x: S) -> Option<&'t S>
pub fn make_safe<S>(&self, x: S) -> Option<&'t S>
version of make that returns Option, but will not panic