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
use std::error::Error;
use std::fmt;

/// An error type for implementors of `DbValue`.
pub enum ConversionError {
    /// The DbValue cannot be converted into the desired rust type.
    ValueType(String),

    /// The DbValue is to big or too small (negative) fo conversion into the desired rust type.
    NumberRange(String),

    /// The DbValue was not yet completely loaded, and further loading is not possible anymore.
    Incomplete(String),
}

impl Error for ConversionError {
    fn description(&self) -> &str {
        match *self {
            ConversionError::ValueType(_) => "value types do not match",
            ConversionError::NumberRange(_) => "number range exceeded",
            ConversionError::Incomplete(_) => "incomplete LOB",
        }
    }
}

impl fmt::Debug for ConversionError {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            ConversionError::ValueType(ref s) |
            ConversionError::NumberRange(ref s) |
            ConversionError::Incomplete(ref s) => {
                write!(formatter, "{}: (\"{}\")", self.description(), s)
            }
        }
    }
}

impl fmt::Display for ConversionError {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            ConversionError::ValueType(ref s) |
            ConversionError::NumberRange(ref s) |
            ConversionError::Incomplete(ref s) => write!(fmt, "{} ", s),
        }
    }
}