Struct Renderer

Source
pub struct Renderer<'writer, 'config> {
    writer: &'writer mut dyn Write,
    config: &'config Config,
}
Expand description

A renderer of display list entries.

The following diagram gives an overview of each of the parts of the renderer’s output:

                    ┌ outer gutter
                    │ ┌ left border
                    │ │ ┌ inner gutter
                    │ │ │   ┌─────────────────────────── source ─────────────────────────────┐
                    │ │ │   │                                                                │
                 ┌────────────────────────────────────────────────────────────────────────────
       header ── │ error[0001]: oh noes, a cupcake has occurred!
snippet start ── │    ┌─ test:9:0
snippet empty ── │    │
 snippet line ── │  9 │   ╭ Cupcake ipsum dolor. Sit amet marshmallow topping cheesecake
 snippet line ── │ 10 │   │ muffin. Halvah croissant candy canes bonbon candy. Apple pie jelly
                 │    │ ╭─│─────────^
snippet break ── │    · │ │
 snippet line ── │ 33 │ │ │ Muffin danish chocolate soufflé pastry icing bonbon oat cake.
 snippet line ── │ 34 │ │ │ Powder cake jujubes oat cake. Lemon drops tootsie roll marshmallow
                 │    │ │ ╰─────────────────────────────^ blah blah
snippet break ── │    · │
 snippet line ── │ 38 │ │   Brownie lemon drops chocolate jelly-o candy canes. Danish marzipan
 snippet line ── │ 39 │ │   jujubes soufflé carrot cake marshmallow tiramisu caramels candy canes.
                 │    │ │           ^^^^^^^^^^^^^^^^^^^ -------------------- blah blah
                 │    │ │           │
                 │    │ │           blah blah
                 │    │ │           note: this is a note
 snippet line ── │ 40 │ │   Fruitcake jelly-o danish toffee. Tootsie roll pastry cheesecake
 snippet line ── │ 41 │ │   soufflé marzipan. Chocolate bar oat cake jujubes lollipop pastry
 snippet line ── │ 42 │ │   cupcake. Candy canes cupcake toffee gingerbread candy canes muffin
                 │    │ │                                ^^^^^^^^^^^^^^^^^^ blah blah
                 │    │ ╰──────────^ blah blah
snippet break ── │    ·
 snippet line ── │ 82 │     gingerbread toffee chupa chups chupa chups jelly-o cotton candy.
                 │    │                 ^^^^^^                         ------- blah blah
snippet empty ── │    │
 snippet note ── │    = blah blah
 snippet note ── │    = blah blah blah
                 │      blah blah
 snippet note ── │    = blah blah blah
                 │      blah blah
        empty ── │

Filler text from http://www.cupcakeipsum.com

Fields§

§writer: &'writer mut dyn Write§config: &'config Config

Implementations§

Source§

impl<'writer, 'config> Renderer<'writer, 'config>

Source

pub fn new( writer: &'writer mut dyn Write, config: &'config Config, ) -> Renderer<'writer, 'config>

Construct a renderer from the given writer and config.

Source

fn chars(&self) -> &'config Chars

Source

pub fn render_header( &mut self, locus: Option<&Locus>, severity: Severity, code: Option<&str>, message: &str, ) -> Result<(), Error>

Diagnostic header, with severity, code, and message.

error[E0001]: unexpected type in `+` application
Source

pub fn render_empty(&mut self) -> Result<(), Error>

Empty line.

Source

pub fn render_snippet_start( &mut self, outer_padding: usize, locus: &Locus, ) -> Result<(), Error>

Top left border and locus.

┌─ test:2:9
Source

pub fn render_snippet_source( &mut self, outer_padding: usize, line_number: usize, source: &str, severity: Severity, single_labels: &[(LabelStyle, Range<usize>, &'_ str)], num_multi_labels: usize, multi_labels: &[(usize, LabelStyle, MultiLabel<'_>)], ) -> Result<(), Error>

A line of source code.

10 │   │ muffin. Halvah croissant candy canes bonbon candy. Apple pie jelly
   │ ╭─│─────────^
Source

pub fn render_snippet_empty( &mut self, outer_padding: usize, severity: Severity, num_multi_labels: usize, multi_labels: &[(usize, LabelStyle, MultiLabel<'_>)], ) -> Result<(), Error>

An empty source line, for providing additional whitespace to source snippets.

│ │ │
Source

pub fn render_snippet_break( &mut self, outer_padding: usize, severity: Severity, num_multi_labels: usize, multi_labels: &[(usize, LabelStyle, MultiLabel<'_>)], ) -> Result<(), Error>

A broken source line, for labeling skipped sections of source.

· │ │
Source

pub fn render_snippet_note( &mut self, outer_padding: usize, message: &str, ) -> Result<(), Error>

Additional notes.

= expected type `Int`
     found type `String`
Source

fn char_metrics( &self, char_indices: impl Iterator<Item = (usize, char)>, ) -> impl Iterator<Item = (Metrics, char)>

Adds tab-stop aware unicode-width computations to an iterator over character indices. Assumes that the character indices begin at the start of the line.

Source

fn snippet_locus(&mut self, locus: &Locus) -> Result<(), Error>

Location focus.

Source

fn outer_gutter(&mut self, outer_padding: usize) -> Result<(), Error>

The outer gutter of a source line.

Source

fn outer_gutter_number( &mut self, line_number: usize, outer_padding: usize, ) -> Result<(), Error>

The outer gutter of a source line, with line number.

Source

fn border_left(&mut self) -> Result<(), Error>

The left-hand border of a source line.

Source

fn border_left_break(&mut self) -> Result<(), Error>

The broken left-hand border of a source line.

Source

fn caret_pointers( &mut self, severity: Severity, max_label_start: usize, single_labels: &[(LabelStyle, Range<usize>, &'_ str)], trailing_label: Option<(usize, &(LabelStyle, Range<usize>, &'_ str))>, char_indices: impl Iterator<Item = (usize, char)>, ) -> Result<(), Error>

Write vertical lines pointing to carets.

Source

fn label_multi_left( &mut self, severity: Severity, label_style: LabelStyle, underline: Option<LabelStyle>, ) -> Result<(), Error>

The left of a multi-line label.

Source

fn label_multi_top_left( &mut self, severity: Severity, label_style: LabelStyle, ) -> Result<(), Error>

The top-left of a multi-line label.

Source

fn label_multi_bottom_left( &mut self, severity: Severity, label_style: LabelStyle, ) -> Result<(), Error>

The bottom left of a multi-line label.

Source

fn label_multi_top_caret( &mut self, severity: Severity, label_style: LabelStyle, source: &str, start: usize, ) -> Result<(), Error>

Multi-line label top.

─────────────^
Source

fn label_multi_bottom_caret( &mut self, severity: Severity, label_style: LabelStyle, source: &str, start: usize, message: &str, ) -> Result<(), Error>

Multi-line label bottom, with a message.

─────────────^ expected `Int` but found `String`
Source

fn inner_gutter_column( &mut self, severity: Severity, underline: Option<(LabelStyle, VerticalBound)>, ) -> Result<(), Error>

Writes an empty gutter space, or continues an underline horizontally.

Source

fn inner_gutter_space(&mut self) -> Result<(), Error>

Writes an empty gutter space.

Source

fn inner_gutter( &mut self, severity: Severity, num_multi_labels: usize, multi_labels: &[(usize, LabelStyle, MultiLabel<'_>)], ) -> Result<(), Error>

Writes an inner gutter, with the left lines if necessary.

Trait Implementations§

Source§

impl Write for Renderer<'_, '_>

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
Source§

fn write_char(&mut self, c: char) -> Result

Writes a char into this writer, returning whether the write succeeded. Read more
Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

§

impl<'writer, 'config> Freeze for Renderer<'writer, 'config>

§

impl<'writer, 'config> !RefUnwindSafe for Renderer<'writer, 'config>

§

impl<'writer, 'config> !Send for Renderer<'writer, 'config>

§

impl<'writer, 'config> !Sync for Renderer<'writer, 'config>

§

impl<'writer, 'config> Unpin for Renderer<'writer, 'config>

§

impl<'writer, 'config> !UnwindSafe for Renderer<'writer, 'config>

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.