Skip to main content

Module highlighter

Module highlighter 

Source
Expand description

This module provides a syntax highlighter for Rust code. It is used by the rustc --explain command.

The syntax highlighter uses rustc_lexerโ€™s tokenize function to parse the Rust code into a Vec of tokens. The highlighter then highlights the tokens in the Vec, and writes the highlighted output to the buffer.

Re-exportsยง

use std::io; ๐Ÿ”’
use std::io::Write; ๐Ÿ”’
use anstyle::AnsiColor; ๐Ÿ”’
use anstyle::Color; ๐Ÿ”’
use anstyle::Effects; ๐Ÿ”’
use anstyle::Style; ๐Ÿ”’
use rustc_lexer::LiteralKind; ๐Ÿ”’
use rustc_lexer::strip_shebang; ๐Ÿ”’
use rustc_lexer::tokenize; ๐Ÿ”’

Structsยง

Highlighter
A syntax highlighter for Rust code It is used by the rustc --explain command.

Constantsยง

DERIVE_COLOR ๐Ÿ”’
FUNCTION_COLOR ๐Ÿ”’
KEYWORDS ๐Ÿ”’
KEYWORD_COLOR ๐Ÿ”’
OTHER_LITERAL_COLOR ๐Ÿ”’
PRIMITIVE_TYPES ๐Ÿ”’
PRIMITIVE_TYPE_COLOR ๐Ÿ”’
STR_LITERAL_COLOR ๐Ÿ”’
TYPE_COLOR ๐Ÿ”’
USE_COLOR ๐Ÿ”’

Functionsยง

highlight
Highlight a Rust code string and write the highlighted output to the buffer. It serves as a wrapper around Highlighter::highlight_rustc_lexer. It is passed to write_anstream_buf in the lib.rs file.