1 | #![deny (rust_2018_idioms)] |
2 | |
3 | //! A library for formatting of text or programming code snippets. |
4 | //! |
5 | //! It's primary purpose is to build an ASCII-graphical representation of the snippet |
6 | //! with annotations. |
7 | //! |
8 | //! # Example |
9 | //! |
10 | //! ```text |
11 | //! error[E0308]: mismatched types |
12 | //! --> src/format.rs:52:1 |
13 | //! | |
14 | //! 51 | ) -> Option<String> { |
15 | //! | -------------- expected `Option<String>` because of return type |
16 | //! 52 | / for ann in annotations { |
17 | //! 53 | | match (ann.range.0, ann.range.1) { |
18 | //! 54 | | (None, None) => continue, |
19 | //! 55 | | (Some(start), Some(end)) if start > end_index => continue, |
20 | //! ... | |
21 | //! 71 | | } |
22 | //! 72 | | } |
23 | //! | |_____^ expected enum `std::option::Option`, found () |
24 | //! ``` |
25 | //! |
26 | //! The crate uses a three stage process with two conversions between states: |
27 | //! |
28 | //! ```text |
29 | //! Snippet --> Renderer --> impl Display |
30 | //! ``` |
31 | //! |
32 | //! The input type - [Snippet] is a structure designed |
33 | //! to align with likely output from any parser whose code snippet is to be |
34 | //! annotated. |
35 | //! |
36 | //! The middle structure - [Renderer] is a structure designed |
37 | //! to convert a snippet into an internal structure that is designed to store |
38 | //! the snippet data in a way that is easy to format. |
39 | //! [Renderer] also handles the user-configurable formatting |
40 | //! options, such as color, or margins. |
41 | //! |
42 | //! Finally, `impl Display` into a final `String` output. |
43 | |
44 | pub mod renderer; |
45 | mod snippet; |
46 | |
47 | #[doc (inline)] |
48 | pub use renderer::Renderer; |
49 | pub use snippet::*; |
50 | |