Struct syntect::highlighting::HighlightState[][src]

pub struct HighlightState {
    pub path: ScopeStack,
    // some fields omitted
}
Expand description

Keeps a stack of scopes and styles as state between highlighting different lines.

If you are highlighting an entire file you create one of these at the start and use it all the way to the end.

Caching

One reason this is exposed is that since it implements Clone you can actually cache these (probably along with a ParseState) and only re-start highlighting from the point of a change. You could also do something fancy like only highlight a bit past the end of a user’s screen and resume highlighting when they scroll down on large files.

Alternatively you can save space by caching only the path field of this struct then re-create the HighlightState when needed by passing that stack as the initial_stack parameter to the new method. This takes less space but a small amount of time to re-create the style stack.

Note: Caching is for advanced users who have tons of time to maximize performance or want to do so eventually. It is not recommended that you try caching the first time you implement highlighting.

Fields

path: ScopeStack

Implementations

Note that the Highlighter is not stored; it is used to construct the initial stack of styles.

Most of the time you’ll want to pass an empty stack as initial_stack, but see the docs for HighlightState for a discussion of advanced caching use cases.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.