Struct ASTContext

Source
pub struct ASTContext {
    pub arena: Bump,
}
Expand description

A context for a GraphQL document which holds an arena allocator.

For the duration of parsing, storing, validating, traversing, and printing an AST its performant and convenient to allocate memory in one chunk for the AST’s operations. This context represents the lifetime of an AST and its derivatives.

An AST Context in other words represents the memory a query and the operations you perform on it take up. This is efficient since once you’re done with the query this entire allocated memory can be dropped all at once. Hence however, it’s inadvisable to reuse the AST Context across multiple incoming GraphQL requests.

Fields§

§arena: Bump

An arena allocator that holds the memory allocated for the AST Context’s lifetime

Implementations§

Source§

impl ASTContext

Source

pub fn new() -> Self

Create a new AST context with a preallocated arena.

Source

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

Put the value of item onto the arena and return a reference to it.

Source

pub fn alloc_str(&self, str: &str) -> &str

Allocate an &str slice onto the arena and return a reference to it.

This is useful when the original slice has an undefined lifetime. This is typically unnecessary for static slices (&'static str) whose lifetimes are as long as the running program and don’t need to be allocated dynamically.

Source

pub fn alloc_string(&self, str: String) -> &str

Puts a String onto the arena and returns a reference to it to tie the String’s lifetime to this AST context without reallocating or copying it.

Trait Implementations§

Source§

impl Default for ASTContext

Source§

fn default() -> Self

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

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.