ErrorReporter

Struct ErrorReporter 

Source
pub struct ErrorReporter { /* private fields */ }
Expand description

Holds metadata about the input, allows to report errors to the user.

This structure should be created before the parsing process and will provide metadata required for the AnnotatedError.

If the reporter contains a file path, then this path must be valid UTF-8. This is needed because the file path is printed on the console when an error is reported.

Implementations§

Source§

impl ErrorReporter

Source

pub fn input_file(path: String, content: String) -> ErrorReporter

Given a file path and its content, creates a new ErrorReporter.

path is not checked to be a valid path.

Source

pub fn non_file_input(content: String) -> ErrorReporter

Creates an ErrorReporter with no file path, just its content.

This can be usefull in situations in which non-file inputs such as STDIN are processed.

Source

pub fn from_path(path: String) -> Result<ErrorReporter, IOError>

Reads the content of path, and creates an ErrorReporter with it.

Source

pub fn path(&self) -> Option<&str>

Returns the file path, if it exists.

Source

pub fn spanned_str(&self) -> SpannedStr<'_>

Returns the SpannedStr associated to the whole input.

§Example
use lisbeth_error::reporter::ErrorReporter;

let file = ErrorReporter::non_file_input("Hello, world".to_string());
assert_eq!(file.spanned_str().content(), "Hello, world");
Source

pub fn format_error<'a>(&'a self, err: &'a AnnotatedError) -> FormattedError<'a>

Constructs a FormattedError from an AnnotatedError.

The returned value can finally be printed to the user.

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