crowbook_localize/
error.rs1use std::error;
6use std::result;
7use std::fmt;
8
9#[derive(Debug, PartialEq)]
11enum ErrorType {
12 Default,
13 Parse,
14}
15
16pub type Result<T> = result::Result<T, Error>;
18
19#[derive(Debug, PartialEq)]
20pub struct Error {
22 msg: String,
23 variant: ErrorType
24}
25
26impl Error {
27 pub fn new<S: Into<String>>(msg: S) -> Error {
29 Error {
30 msg: msg.into(),
31 variant: ErrorType::Default,
32 }
33 }
34
35 pub fn parse<S: Into<String>>(msg: S) -> Error {
37 Error {
38 msg: msg.into(),
39 variant: ErrorType::Parse,
40 }
41 }
42}
43
44impl error::Error for Error {
45 fn description(&self) -> &str {
46 &self.msg
47 }
48}
49
50impl fmt::Display for Error {
51 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52 match self.variant {
53 ErrorType::Parse => write!(f, "Error parsing localization file: {}", self.msg),
54 _ => write!(f, "{}", self.msg),
55 }
56 }
57}
58