Formatted

Struct Formatted 

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

A diagnostic formatted for printing.

A Formatted can be printing and converted to a string directly via it’s Display implementation.

Alternatively, you can iterate over the individual Lines and from there over pairs of &str and Style. This allows you to apply custom styling (e.g. colors) to individual parts of the diagnostic.

Formatted also provides a short one-line summary.

§Example

use aldrin_parser::{Diagnostic, Parser};

let parsed = Parser::new().parse("schemas/duplicate_id.aldrin");
let err = &parsed.errors()[0];
let formatted = err.format(&parsed);

// Print via Display:
eprintln!("{}", formatted);

// Print a one-line summary:
eprintln!("Error: {}.", formatted.summary());

// Print manually to apply styling to the output:
for line in &formatted {
    for (chunk, style) in line {
        // Apply style to chunk, e.g. colorize the output.
        eprint!("{}", chunk);
    }

    eprintln!();
}

Implementations§

Source§

impl<'a> Formatted<'a>

Source

pub fn kind(&self) -> DiagnosticKind

Kind of the diagnostic; error or warning.

Source

pub fn summary(&self) -> &str

Short one-line summary.

The summary begins with a lower-case letter and doesn’t end with any punctuation.

§Example
eprintln!("An issue occurred: {}.", formatted.summary());
Source

pub fn len(&self) -> usize

Returns the number of lines.

Source

pub fn lines(&'a self) -> Lines<'a>

Returns an iterator over the lines.

Trait Implementations§

Source§

impl<'a> Clone for Formatted<'a>

Source§

fn clone(&self) -> Formatted<'a>

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<'a> Debug for Formatted<'a>

Source§

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

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

impl Display for Formatted<'_>

Source§

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

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

impl<'a> IntoIterator for &'a Formatted<'a>

Source§

type Item = &'a Line<'a>

The type of the elements being iterated over.
Source§

type IntoIter = Lines<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Formatted<'a>

§

impl<'a> RefUnwindSafe for Formatted<'a>

§

impl<'a> Send for Formatted<'a>

§

impl<'a> Sync for Formatted<'a>

§

impl<'a> Unpin for Formatted<'a>

§

impl<'a> UnwindSafe for Formatted<'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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.