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
use std::error::Error;
use std::fmt;
use std::result;
use std::num::ParseFloatError;
pub type Result<T> = result::Result<T, TinyExprError>;
#[derive(Debug)]
pub enum TinyExprError {
Parse(ParseFloatError),
Other(String)
}
impl fmt::Display for TinyExprError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TinyExprError::Parse(ref err) => err.fmt(f),
TinyExprError::Other(ref err) => err.fmt(f)
}
}
}
impl Error for TinyExprError {
fn description(&self) -> &str {
match *self {
TinyExprError::Parse(ref err) => err.description(),
TinyExprError::Other(ref err) => err
}
}
}
impl From<String> for TinyExprError {
fn from(err: String) -> TinyExprError {
TinyExprError::Other(err)
}
}
impl From<ParseFloatError> for TinyExprError {
fn from(err: ParseFloatError) -> TinyExprError {
TinyExprError::Parse(err)
}
}