Skip to main content

Renderer

Struct Renderer 

pub struct Renderer { /* private fields */ }
Expand description

The Renderer for a [Report]

The caller is expected to detect any relevant terminal features and configure the renderer, including

§Example

let report = // ...

let renderer = Renderer::styled();
let output = renderer.render(report);
anstream::println!("{output}");

Implementations§

§

impl Renderer

pub const fn plain() -> Renderer

No terminal styling

pub const fn styled() -> Renderer

Default terminal styling

If ANSI escape codes are not supported, either

§Note

When testing styled terminal output, see the testing-colors feature

pub const fn short_message(self, short_message: bool) -> Renderer

Abbreviate the message

pub const fn term_width(self, term_width: usize) -> Renderer

Set the width to render within

Affects the rendering of [Snippet][crate::Snippet]s

pub const fn decor_style(self, decor_style: DecorStyle) -> Renderer

Set the character set used for rendering decor

pub const fn anonymized_line_numbers( self, anonymized_line_numbers: bool, ) -> Renderer

Anonymize line numbers

When enabled, line numbers are replaced with LL which is useful for tests.

§Example
  --> $DIR/whitespace-trimming.rs:4:193
   |
LL | ...                   let _: () = 42;
   |                                   ^^ expected (), found integer
   |
§

impl Renderer

pub fn render(&self, groups: &[Group<'_>]) -> String

Render a diagnostic [Report]

§

impl Renderer

Customize Renderer::styled

pub const fn error(self, style: Style) -> Renderer

Override the output style for [error][crate::Level::ERROR]

pub const fn warning(self, style: Style) -> Renderer

Override the output style for [warnings][crate::Level::WARNING]

pub const fn info(self, style: Style) -> Renderer

Override the output style for [info][crate::Level::INFO]

pub const fn note(self, style: Style) -> Renderer

Override the output style for [notes][crate::Level::NOTE]

pub const fn help(self, style: Style) -> Renderer

Override the output style for [help][crate::Level::HELP]

pub const fn line_num(self, style: Style) -> Renderer

Override the output style for line numbers in the [Snippet][crate::Snippet] gutter

pub const fn emphasis(self, style: Style) -> Renderer

Override the output style for emphasis for the [primary_title][crate::Level::primary_title]

pub const fn context(self, style: Style) -> Renderer

Override the output style for [AnnotationKind::Context][crate::AnnotationKind::Context]

pub const fn addition(self, style: Style) -> Renderer

Override the output style for [Patch][crate::Patch] additions

pub const fn removal(self, style: Style) -> Renderer

Override the output style for [Patch][crate::Patch] removals

pub const fn none(self, style: Style) -> Renderer

Override the output style for all other text

Trait Implementations§

§

impl Clone for Renderer

§

fn clone(&self) -> Renderer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Renderer

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> InitializeFromFunction<T> for T

§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

§

fn super_from(input: T) -> O

Convert from a type to another type.
§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more