pub struct CodeHighlighter { /* private fields */ }Expand description
A syntax highlighter for a specific language.
Stores a reference to the static SyntaxReference and creates a fresh
HighlightLines on demand — no unsafe code needed.
Implementations§
Source§impl CodeHighlighter
impl CodeHighlighter
Sourcepub fn new(lang: &str) -> Self
pub fn new(lang: &str) -> Self
Create a highlighter for the given language hint (e.g., “rust”, “python”).
Maintains parse state across calls to highlight_spans_stateful()
so multiline strings, comments, and heredocs highlight correctly.
Use highlight_spans() for one-off single-line highlighting.
Sourcepub fn highlight_spans(&mut self, line: &str) -> Vec<Span<'static>>
pub fn highlight_spans(&mut self, line: &str) -> Vec<Span<'static>>
Highlight a line and return ratatui Spans with foreground colors.
Stateful — parse state carries across calls, so multiline strings/comments highlight correctly. Call lines in order.
No background is set — the caller controls backgrounds for diff rendering.
Auto Trait Implementations§
impl Freeze for CodeHighlighter
impl RefUnwindSafe for CodeHighlighter
impl Send for CodeHighlighter
impl Sync for CodeHighlighter
impl Unpin for CodeHighlighter
impl UnsafeUnpin for CodeHighlighter
impl UnwindSafe for CodeHighlighter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more