Skip to main content

Document

Struct Document 

Source
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>

Source

pub fn source(&self) -> &str

Return the current source.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<B> Forget for Document<B>

§

impl<B> Freeze for Document<B>
where B: Freeze, Registry<B>: Freeze, Option<Syntax<B>>: Freeze,

§

impl<B> Move for Document<B>

§

impl<B> RefUnwindSafe for Document<B>
where B: RefUnwindSafe, Registry<B>: RefUnwindSafe, Option<Syntax<B>>: RefUnwindSafe,

§

impl<B> Send for Document<B>
where B: Send, Registry<B>: Send, Option<Syntax<B>>: Send,

§

impl<B> Sync for Document<B>
where B: Sync, Registry<B>: Sync, Option<Syntax<B>>: Sync,

§

impl<B> Unpin for Document<B>
where B: Unpin, Registry<B>: Unpin, Option<Syntax<B>>: Unpin,

§

impl<B> UnsafeUnpin for Document<B>
where B: UnsafeUnpin, Registry<B>: UnsafeUnpin, Option<Syntax<B>>: UnsafeUnpin,

§

impl<B> UnwindSafe for Document<B>
where B: UnwindSafe, Registry<B>: UnwindSafe, Option<Syntax<B>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.