Struct Error

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

An error formatter.

Implementations§

Source§

impl Error

Source

pub fn new(label: impl ToString) -> Self

Create a new Error formatter.

Examples found in repository?
examples/error.rs (line 10)
3fn main() {
4    let src = r#"This is an example
5content of the slice
6which will be annotated
7with the list of annotations below.
8"#;
9
10    let msg = Error::new("expected type, found `x`")
11        .error(260, 0, 12, src, "found `x`")
12        .help("try using a foobs intead")
13        .to_string();
14
15    println!("{}", msg);
16}
More examples
Hide additional examples
examples/cursor.rs (line 18)
4fn main() {
5    let cursor = Cursor::new(
6        r#"This is an example
7content of the slice
8which will be annotated
9with the list of annotations below.
10"#,
11    );
12
13    let line = 1;
14    let start = cursor.position() as usize;
15    let end = cursor.get_ref().len() as usize;
16    let code = cursor.into_inner();
17
18    let msg = Error::new("expected type, found `x`")
19        .error(line, start, end, code, "found `x`")
20        .help("try using a foobs instead")
21        .to_string();
22
23    println!("{}", msg);
24}
Source

pub fn error( self, line_start: usize, start: usize, end: usize, source: impl ToString, label: impl ToString, ) -> Self

Pass a new error to the formatter.

Examples found in repository?
examples/error.rs (line 11)
3fn main() {
4    let src = r#"This is an example
5content of the slice
6which will be annotated
7with the list of annotations below.
8"#;
9
10    let msg = Error::new("expected type, found `x`")
11        .error(260, 0, 12, src, "found `x`")
12        .help("try using a foobs intead")
13        .to_string();
14
15    println!("{}", msg);
16}
More examples
Hide additional examples
examples/cursor.rs (line 19)
4fn main() {
5    let cursor = Cursor::new(
6        r#"This is an example
7content of the slice
8which will be annotated
9with the list of annotations below.
10"#,
11    );
12
13    let line = 1;
14    let start = cursor.position() as usize;
15    let end = cursor.get_ref().len() as usize;
16    let code = cursor.into_inner();
17
18    let msg = Error::new("expected type, found `x`")
19        .error(line, start, end, code, "found `x`")
20        .help("try using a foobs instead")
21        .to_string();
22
23    println!("{}", msg);
24}
Source

pub fn help(self, label: impl ToString) -> Self

Create a new footer.

Examples found in repository?
examples/error.rs (line 12)
3fn main() {
4    let src = r#"This is an example
5content of the slice
6which will be annotated
7with the list of annotations below.
8"#;
9
10    let msg = Error::new("expected type, found `x`")
11        .error(260, 0, 12, src, "found `x`")
12        .help("try using a foobs intead")
13        .to_string();
14
15    println!("{}", msg);
16}
More examples
Hide additional examples
examples/cursor.rs (line 20)
4fn main() {
5    let cursor = Cursor::new(
6        r#"This is an example
7content of the slice
8which will be annotated
9with the list of annotations below.
10"#,
11    );
12
13    let line = 1;
14    let start = cursor.position() as usize;
15    let end = cursor.get_ref().len() as usize;
16    let code = cursor.into_inner();
17
18    let msg = Error::new("expected type, found `x`")
19        .error(line, start, end, code, "found `x`")
20        .help("try using a foobs instead")
21        .to_string();
22
23    println!("{}", msg);
24}
Source

pub fn to_string(self) -> String

Examples found in repository?
examples/error.rs (line 13)
3fn main() {
4    let src = r#"This is an example
5content of the slice
6which will be annotated
7with the list of annotations below.
8"#;
9
10    let msg = Error::new("expected type, found `x`")
11        .error(260, 0, 12, src, "found `x`")
12        .help("try using a foobs intead")
13        .to_string();
14
15    println!("{}", msg);
16}
More examples
Hide additional examples
examples/cursor.rs (line 21)
4fn main() {
5    let cursor = Cursor::new(
6        r#"This is an example
7content of the slice
8which will be annotated
9with the list of annotations below.
10"#,
11    );
12
13    let line = 1;
14    let start = cursor.position() as usize;
15    let end = cursor.get_ref().len() as usize;
16    let code = cursor.into_inner();
17
18    let msg = Error::new("expected type, found `x`")
19        .error(line, start, end, code, "found `x`")
20        .help("try using a foobs instead")
21        .to_string();
22
23    println!("{}", msg);
24}

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnwindSafe for Error

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.