[][src]Trait rustdoc_highlight::Writer

pub trait Writer {
    fn enter_span(&mut self, _: Class) -> Result<()>;
fn exit_span(&mut self) -> Result<()>;
fn string<T: Display>(
        &mut self,
        text: T,
        klass: Class,
        tok: Option<Token>
    ) -> Result<()>; }

Trait that controls writing the output of syntax highlighting. Users should implement this trait to customise writing output.

The classifier will call into the Writer implementation as it finds spans of text to highlight. Exactly how that text should be highlighted is up to the implementation.

Required methods

fn enter_span(&mut self, _: Class) -> Result<()>

Called when we start processing a span of text that should be highlighted. The Class argument specifies how it should be highlighted.

fn exit_span(&mut self) -> Result<()>

Called at the end of a span of highlighted text.

fn string<T: Display>(
    &mut self,
    text: T,
    klass: Class,
    tok: Option<Token>
) -> Result<()>

Called for a span of text, usually, but not always, a single token. If the string of text (T) does correspond to a token, then the token will also be passed. If the text should be highlighted differently from the surrounding text, then the Class argument will be a value other than None. The following sequences of callbacks are equivalent:

    enter_span(Foo), string("text", None), exit_span()
    string("text", Foo)

The latter can be thought of as a shorthand for the former, which is more flexible.

Loading content...

Implementors

impl<U: Write> Writer for U[src]

Loading content...