Config

Struct Config 

Source
pub struct Config<'a> { /* private fields */ }
Expand description

Configuration for the diagnostic renderer

Implementations§

Source§

impl<'a> Config<'a>

Source

pub fn new() -> Self

Create a new config with default values.

Source

pub fn with_cross_gap(self, enabled: bool) -> Self

Enable or disable cross gap rendering.

When enabled, vertical bars between labels are drawn with gaps for better visual clarity when labels overlap.

Default: depends on C library default

Source

pub fn with_compact(self, enabled: bool) -> Self

Enable or disable compact mode.

In compact mode, the diagnostic output is more condensed:

  • Underlines and arrows may be merged onto the same line
  • Only meaningful label arrows are shown

Works with underlines enabled or disabled.

Default: false

Source

pub fn with_underlines(self, enabled: bool) -> Self

Enable or disable underlines for highlighted spans.

When enabled, spans are underlined with characters like ^^^. When disabled, only label arrows are shown.

Works with both compact and non-compact modes.

Default: true

Source

pub fn with_column_order(self, enabled: bool) -> Self

Enable or disable natural label ordering.

When disabled (default), labels are sorted to minimize line crossings:

  • Inline labels appear first, ordered by reverse column position
  • Multi-line labels follow, with tails before heads

When enabled, labels are simply sorted by column position.

Default: false (natural ordering enabled)

§Example
let config = Config::new().with_column_order(true);  // Simple column order
Source

pub fn with_align_messages(self, enabled: bool) -> Self

Enable or disable aligned label messages.

When enabled (default), label messages are aligned to the same column, producing a more structured appearance with longer arrows.

When disabled, messages are placed immediately after their arrows, creating more compact output.

Default: true (aligned)

§Example
let config = Config::new().with_align_messages(false);  // Compact arrows
Source

pub fn with_multiline_arrows(self, enabled: bool) -> Self

Enable or disable multiline arrows for labels.

When enabled, labels that span multiple lines will have arrows drawn across all covered lines.

Default: true

Source

pub fn with_tab_width(self, width: i32) -> Self

Set the tab width for rendering.

Tab characters (\t) in source code are expanded to this many spaces.

Default: 4

§Example
let config = Config::new().with_tab_width(8);  // 8-space tabs
Source

pub fn with_limit_width(self, width: i32) -> Self

Set the width limit for line wrapping.

Lines longer than this width will be truncated with an ellipsis. Set to 0 for no limit (lines can be arbitrarily long).

Default: 0 (no limit)

§Example
let config = Config::new().with_limit_width(80);  // Wrap at 80 columns
Source

pub fn with_ambi_width(self, width: i32) -> Self

Set the ambiguous character width.

Some Unicode characters have ambiguous width (e.g., East Asian characters). This setting determines their display width:

  • 1 - Treat as narrow (1 column)
  • 2 - Treat as wide (2 columns)

Default: 1

§Example
let config = Config::new().with_ambi_width(2);  // East Asian width
Source

pub fn with_label_attach(self, attach: LabelAttach) -> Self

Set where labels attach to spans.

Controls the default attachment point for all labels. Individual labels can override this with Report::with_order.

Default: LabelAttach::Middle

Source

pub fn with_index_type(self, index_type: IndexType) -> Self

Set the index type (character or byte).

Determines how span ranges are interpreted. See IndexType for details.

Default: IndexType::Char

Source

pub fn with_char_set_ascii(self) -> Self

Set ASCII character set for rendering.

Uses ASCII characters (-, |, +, etc.) for box drawing. This is compatible with all terminals and file formats.

§Example
Error: message
   ,-[ file.rs:1:1 ]
   |
 1 | code here
   | ^^|^
   |   `--- label
---'
Source

pub fn with_char_set_unicode(self) -> Self

Set Unicode character set for rendering.

Uses Unicode box-drawing characters (─, │, ┬, etc.) for prettier output. Requires a terminal that supports Unicode.

§Example
Error: message
   ╭─[ file.rs:1:1 ]
   │
 1 │ code here
   │ ──┬─
   │   ╰─── label
───╯
Source

pub fn with_char_set(self, char_set: &'a CharSet) -> Self

Set a custom character set for rendering.

Allows fine-grained control over all box-drawing characters. The character set must outlive the config.

§Example
let custom = CharSet {
    hbar: '=',
    vbar: '!',
    ..CharSet::ascii()
};
let config = Config::new().with_char_set(&custom);
Source

pub fn with_color_default(self) -> Self

Enable default ANSI colors.

Uses the built-in color scheme with standard ANSI escape codes:

  • Errors in red
  • Warnings in yellow
  • Margins in blue
  • etc.

This is appropriate for terminal output.

Source

pub fn with_color_disabled(self) -> Self

Disable color output.

All output will be plain text without ANSI escape codes. This is appropriate for file output or non-color terminals.

Default: colors are disabled

Source

pub fn with_color<C>(self, color: &'a C) -> Self
where C: Color,

Set a custom color provider.

Trait Implementations§

Source§

impl Clone for Config<'_>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Config<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Config<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Config<'a>

§

impl<'a> RefUnwindSafe for Config<'a>

§

impl<'a> !Send for Config<'a>

§

impl<'a> !Sync for Config<'a>

§

impl<'a> Unpin for Config<'a>

§

impl<'a> UnwindSafe for Config<'a>

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

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