pub trait Doc:
Clone
+ Debug
+ Send
+ Sync
+ 'static {
type Source: Content;
type Lang: Language;
type Node<'r>: SgNode<'r>;
// Required methods
fn get_lang(&self) -> &Self::Lang;
fn get_source(&self) -> &Self::Source;
fn do_edit(&mut self, edit: &Edit<Self::Source>) -> Result<(), String>;
fn root_node(&self) -> Self::Node<'_>;
fn get_node_text<'a>(&'a self, node: &Self::Node<'a>) -> Cow<'a, str>;
}Expand description
Represents a source code document with its language and parsed AST.
Doc provides the core interface for working with parsed source code documents.
It combines the source text, language information, and AST representation in
a single abstraction that supports editing and node operations.
§Type Parameters
Source: Content- The text representation (String, UTF-16, etc.)Lang: Language- The programming language implementationNode: SgNode- The AST node implementation
§Example
ⓘ
// Documents provide access to source, language, and AST
let doc = StrDoc::new("const x = 42;", JavaScript);
// Access different aspects of the document
let source = doc.get_source(); // Get source text
let lang = doc.get_lang(); // Get language info
let root = doc.root_node(); // Get AST root
// Extract text from specific nodes
let node_text = doc.get_node_text(&some_node);Required Associated Types§
Required Methods§
Sourcefn get_source(&self) -> &Self::Source
fn get_source(&self) -> &Self::Source
Get the source code content
Sourcefn do_edit(&mut self, edit: &Edit<Self::Source>) -> Result<(), String>
fn do_edit(&mut self, edit: &Edit<Self::Source>) -> Result<(), String>
Apply an edit to the document, updating both source and AST
Sourcefn get_node_text<'a>(&'a self, node: &Self::Node<'a>) -> Cow<'a, str>
fn get_node_text<'a>(&'a self, node: &Self::Node<'a>) -> Cow<'a, str>
Extract the text content of a specific AST node
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.