pub struct Error { /* private fields */ }Expand description
An error formatter.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(label: impl ToString) -> Self
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
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}Sourcepub fn error(
self,
line_start: usize,
start: usize,
end: usize,
source: impl ToString,
label: impl ToString,
) -> Self
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
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}Sourcepub fn help(self, label: impl ToString) -> Self
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
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}Sourcepub fn to_string(self) -> String
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
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 UnsafeUnpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more