Skip to main content

LineBuffer

Struct LineBuffer 

Source
pub struct LineBuffer {
    pub scopes: Vec<ScopeSpan>,
    pub styles: Vec<StyleSpan>,
    /* private fields */
}
Expand description

Scratch space for highlighting one line without reallocating per call.

A buffer holds the latest tokenization and styling results so callers can reuse allocations while scanning many lines or repeatedly re-highlighting a changing line.

Fields§

§scopes: Vec<ScopeSpan>

Current scope spans.

§styles: Vec<StyleSpan>

Current style spans.

Implementations§

Source§

impl LineBuffer

Source

pub fn clear(&mut self)

Clears all buffered spans while retaining allocations.

Cached scope styles are intentionally retained: they are keyed by (theme, grammar, scope_count) and stays valid across line resets.

Source

pub fn tokenize<'a>( &'a mut self, grammar: &Grammar, state: &mut LineState, line: &str, ) -> &'a [ScopeSpan]

Tokenizes one line into this reusable buffer.

Source

pub fn style<'a>( &'a mut self, grammar: &Grammar, theme: &Theme, line: &str, ) -> &'a [StyleSpan]

Applies a theme to this buffer’s current scope spans.

Source

pub fn highlight<'a>( &'a mut self, grammar: &Grammar, theme: &Theme, state: &mut LineState, line: &str, ) -> (&'a [ScopeSpan], &'a [StyleSpan])

Tokenizes and styles one line into this reusable buffer.

Trait Implementations§

Source§

impl Debug for LineBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LineBuffer

Source§

fn default() -> LineBuffer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.