1use std::error::Error;
4use std::fmt;
5use std::result;
6use std::num::ParseFloatError;
7
8pub type Result<T> = result::Result<T, TinyExprError>;
10
11#[derive(Debug)]
13pub enum TinyExprError {
14 Parse(ParseFloatError),
16 Other(String)
18}
19
20impl fmt::Display for TinyExprError {
21 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22 match *self {
23 TinyExprError::Parse(ref err) => err.fmt(f),
24 TinyExprError::Other(ref err) => err.fmt(f)
25 }
26 }
27}
28
29impl Error for TinyExprError {
30 fn description(&self) -> &str {
31 match *self {
32 TinyExprError::Parse(ref err) => err.description(),
33 TinyExprError::Other(ref err) => err
34 }
35 }
36}
37
38impl From<String> for TinyExprError {
39 fn from(err: String) -> TinyExprError {
40 TinyExprError::Other(err)
41 }
42}
43
44impl From<ParseFloatError> for TinyExprError {
45 fn from(err: ParseFloatError) -> TinyExprError {
46 TinyExprError::Parse(err)
47 }
48}