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
41
42
43
44
45
46
47
48
49
50
51
52
pub mod errors {
    use std::error::Error;
    use std::fmt;

    #[derive(Debug, Clone)]
    pub enum TErrorKind {
        BadFormat,
        DateOverflow,
        WeekDay,
        AllocTickerError,
        MutexError,
        Other(String),
    }

    #[derive(Debug,Clone)]
    pub struct TError {
        kind:TErrorKind,
        error:String,
    }

    impl TError {
        pub fn new(vkind:TErrorKind) -> TError {
            TError { kind:vkind.clone(),
                error: match vkind {
                TErrorKind::BadFormat => { String::from("error,bad date format...") }
                TErrorKind::DateOverflow => {  String::from("error,Date overflow...") }
                TErrorKind::WeekDay => { String::from("error,bad week day...") }
                TErrorKind::AllocTickerError  => { String::from("bad alloc ticker...") }
                    TErrorKind::MutexError => { String::from("get mutex lock error...") }
                TErrorKind::Other(v) => { v.clone() }
            } }
        }

        pub fn kind(&self) -> &TErrorKind {
            &self.kind
        }

        pub fn last_error(&self) -> &String {
            &self.error
        }
    }

    impl Error for TError {}

    impl fmt::Display for TError {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f,"{}",self.error)
        }
    }

    pub type TResult<T> = Result<T,TError>;
}