1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::fmt;
use ansi_term::Colour;
#[derive(Debug)]
pub enum ErrorLevel {
Info,
Warning,
Error,
}
#[derive(Debug)]
pub struct Error(pub (ErrorLevel, String));
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let colour_level = match (self.0).0 {
ErrorLevel::Info => Colour::Yellow.paint("Info"),
ErrorLevel::Warning => Colour::RGB(255, 210, 0).paint("Warning"),
ErrorLevel::Error => Colour::Red.paint("Error"),
};
write!(f, "[{}] {}", colour_level, (self.0).1)
}
}
#[derive(Debug)]
pub struct ErrorStack(pub Vec<Error>);
impl fmt::Display for ErrorStack {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for error in &self.0 {
write!(f, "{}", error).unwrap();
}
write!(f, "")
}
}