chic/lib.rs
1//! Pretty parser error reporting.
2//!
3//! # Examples
4//!
5//! ```
6//! use chic::Error;
7//!
8//! let src = r#"This is an example
9//! content of the slice
10//! which will be annotated
11//! with the list of annotations below.
12//! "#;
13//!
14//! let msg = Error::new("expected type, found `x`")
15//! .error(260, 0, 12, src, "found `x`")
16//! .help("try using a foobs intead")
17//! .to_string();
18//!
19//! println!("{}", msg);
20//! ```
21//!
22//! Outputs:
23//!
24//! ```txt
25//! error: expected type, found `x`
26//! |
27//! 260 | This is an example
28//! | ^^^^^^^^^^^^ found `x`
29//! |
30//! = help: try using a foobs instead
31//! ```
32//!
33//! Or convert an `io::Cursor` to an annotated error:
34//!
35//! ```
36//! use std::io::Cursor;
37//! use chic::Error;
38//!
39//! let cursor = Cursor::new(
40//! r#"This is an example
41//! content of the slice
42//! which will be annotated
43//! with the list of annotations below.
44//! "#,
45//! );
46//!
47//! let line = 1;
48//! let start = cursor.position() as usize;
49//! let end = cursor.get_ref().len() as usize;
50//! let code = cursor.into_inner();
51//!
52//! let msg = Error::new("expected type, found `x`")
53//! .error(line, start, end, code, "found `x`")
54//! .help("try using a foobs instead")
55//! .to_string();
56//!
57//! println!("{}", msg);
58//! ```
59
60pub use error::Error;
61pub use warning::Warning;
62
63mod error;
64mod warning;