[][src]Crate show_my_errors

This is a library to display simple errors in colorful, rustc-like way. It can't show multi-line errors or draw arrows between parts of code, but its interface is simple and easy to use. If you want something more complex, you probably should use annotate-snippets, which is used by rustc itself.

Basic usage

Entry point of this library is AnnotationList. You should create it, add some errors and then use .show_stderr() or .show_stdout() with some Stylesheet to display the message.

let mut list = AnnotationList::new("hello.txt", "Hello world!");
list
    .warning(4..7, "punctuation problem", "you probably forgot a comma")?
    .info(0..0, "consider adding some translations", None)?;
assert_eq!(list.to_string()?, r#"warning: punctuation problem
  --> hello.txt:1:5
   |
 1 | Hello world!
   |     ^^^ you probably forgot a comma

info: consider adding some translations
  --> hello.txt:1:1
   |
 1 | Hello world!
   |
"#);

Structs

Annotation

Info about annotation. You can create these manually and then pass to AnnotationList::add or just use AnnotationLists helper methods

AnnotationList

List of annotations applied to some input string. Doesn't owns string, so has a limited lifetime.

Stylesheet

Set of styles to colorize the output

Enums

Error

Errors that can occure while constructing AnnotationList. Fields of each variant are the start and the end of range, respectively.

Severity

Annotation severity

Traits

AnnotationText

Something that can be converted to Option<String>. You probably shouldn't implement this trait yourself, it's here only to simplify annotation creation syntax.

Type Definitions

Result