pub struct Document<B: Backend> { /* private fields */ }Expand description
A source document that shares compiled queries with its language registry.
The document keeps the languages loaded at creation. Source updates reuse the root tree and compatible embedded-language trees. Highlighting queries rerun only when the source or rainbow option changes. Dropping the document releases its trees.
Implementations§
Source§impl<B: Backend> Document<B>
impl<B: Backend> Document<B>
Sourcepub fn update(&mut self, source: &str) -> Result<(), Error>
pub fn update(&mut self, source: &str) -> Result<(), Error>
Replace the source and reuse compatible trees with a UTF-8-safe edit. If the source is unchanged, do nothing. A failed parse leaves the source unchanged. The source buffer retains its capacity for subsequent updates.
§Errors
Returns an error if parsing or query compilation fails, or injection nesting is too deep.
Sourcepub fn highlight(
&mut self,
config: &HighlightConfig,
) -> Result<HighlightResult, Error>
pub fn highlight( &mut self, config: &HighlightConfig, ) -> Result<HighlightResult, Error>
Return an owned snapshot. Changes to line emphasis reuse cached highlighting. Snapshots remain valid after the document is edited or dropped.
Sourcepub fn highlight_ref(
&mut self,
config: &HighlightConfig,
) -> Result<&HighlightResult, Error>
pub fn highlight_ref( &mut self, config: &HighlightConfig, ) -> Result<&HighlightResult, Error>
Borrow cached highlighting without cloning tokens. The source cannot be updated while the output is borrowed.
§Errors
Returns an error if parsing or highlighting fails.