pub trait PrintNode {
// Required method
fn write_to_buffer(&self, level: usize, buffer: &mut dyn Write) -> Result;
// Provided method
fn print(&self) -> String { ... }
}
Expand description
Trait for printing AST Nodes to a new String allocated on the heap.
This is implemented by all AST Nodes and can hence be used to granularly print GraphQL language.
However, mostly this will be used via Document::print
.
This typically is the last operation that’s done in a given AST context and is hence outside of its lifetime and arena.
For convience when debugging, AST Nodes that implement PrintNode
also automatically
implement the fmt::Display
trait.
Required Methods§
Sourcefn write_to_buffer(&self, level: usize, buffer: &mut dyn Write) -> Result
fn write_to_buffer(&self, level: usize, buffer: &mut dyn Write) -> Result
Write an AST node to a buffer implementing the Write trait.
The level
indicates the level of nesting, which increases with each SelectionSet
and is typically initialized as zero (0
).
Provided Methods§
Sourcefn print(&self) -> String
fn print(&self) -> String
Print an AST Node to source text as a String allocated on the heap.
For convience when debugging, AST Nodes that implement PrintNode
also automatically
implement the fmt::Display
trait.