pub trait Builder<L: Language> {
// Required method
fn build<'a, S: Source + ?Sized>(
&self,
text: &S,
edits: &[TextEdit],
cache: &'a mut impl BuilderCache<L>,
) -> BuildOutput<L>;
}Expand description
Trait for building higher-level structures (like ASTs) from a green tree.
While the [Parser] produces a generic GreenNode tree, the Builder is
responsible for “lowering” or “binding” this tree into a more ergonomic,
language-specific structure (e.g., an AST with typed nodes).
§Usage Scenario
The Builder is typically used after parsing to:
- Traverse the produced
GreenNodetree. - Construct typed AST nodes.
- Cache these typed nodes for incremental updates.
Required Methods§
Sourcefn build<'a, S: Source + ?Sized>(
&self,
text: &S,
edits: &[TextEdit],
cache: &'a mut impl BuilderCache<L>,
) -> BuildOutput<L>
fn build<'a, S: Source + ?Sized>( &self, text: &S, edits: &[TextEdit], cache: &'a mut impl BuilderCache<L>, ) -> BuildOutput<L>
Builds the higher-level structure (typically an AST) from the source text.
This method is the primary entry point for converting a raw source or a syntax tree into a typed AST. It handles incremental rebuilding if edits and a cache are provided.
§Arguments
text- The source text to build from.edits- A slice ofTextEdits representing changes since the last build. Empty if building from scratch.cache- ABuilderCachefor incremental reuse and resource management.
§Returns
A BuildOutput containing the typed root node and any diagnostics.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.