Struct codespan_reporting::term::renderer::Renderer

source ·
pub struct Renderer<'writer, 'config> {
    writer: &'writer mut dyn WriteColor,
    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 WriteColor§config: &'config Config

Implementations§

source§

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

source

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

Construct a renderer from the given writer and config.

source

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

source

fn styles(&self) -> &'config Styles

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<'writer, 'config> Write for Renderer<'writer, 'config>

source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

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

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · source§

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

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
source§

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

source§

fn supports_color(&self) -> bool

Returns true if and only if the underlying writer supports colors.
source§

fn set_color(&mut self, spec: &ColorSpec) -> Result<()>

Set the color settings of the writer. Read more
source§

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

Reset the current color settings to their original settings. Read more
source§

fn is_synchronous(&self) -> bool

Returns true if and only if the underlying writer must synchronously interact with an end user’s device in order to control colors. By default, this always returns false. Read more
Set the current hyperlink of the writer. Read more
Returns true if and only if the underlying writer supports hyperlinks. 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>,

§

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>,

§

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.