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
impl ASTContext
Sourcepub fn alloc<T>(&self, item: T) -> &T
pub fn alloc<T>(&self, item: T) -> &T
Put the value of item
onto the arena and return a reference to it.
Sourcepub fn alloc_str(&self, str: &str) -> &str
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.
Sourcepub fn alloc_string(&self, str: String) -> &str
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.