blackjack/error/
mod.rs

1//! The common Error(s) and associated implementations used in within the crate
2
3use failure::Fail;
4
5/// Common error enum for the crate
6#[derive(Debug, Fail)]
7pub enum BlackJackError {
8    /// A failure of not having the `Series` name set, where one was expected
9    #[fail(display = "No series name present!")]
10    NoSeriesName,
11
12    /// A failure to decode a `Series<T>` which was previously encoded to `SerializedSeries`
13    #[fail(display = "Unable to decode series")]
14    SerializationDecodeError(Box<bincode::ErrorKind>),
15
16    /// Failure to parse the header of a CSV file.
17    #[fail(display = "Unable to read headers!")]
18    HeaderParseError(csv::Error),
19
20    /// Failure of a general `std::io::Error`
21    #[fail(display = "IO error")]
22    IoError(std::io::Error),
23
24    /// Failure due to mismatched sizes
25    #[fail(display = "ValueError")]
26    ValueError(String),
27
28    /// Length mismatch
29    #[fail(display = "LengthMismatch")]
30    LengthMismatch(String),
31}
32
33impl From<&str> for BlackJackError {
34    fn from(error: &str) -> BlackJackError {
35        BlackJackError::ValueError(error.to_owned())
36    }
37}
38
39impl From<std::io::Error> for BlackJackError {
40    fn from(error: std::io::Error) -> BlackJackError {
41        BlackJackError::IoError(error)
42    }
43}
44
45impl From<csv::Error> for BlackJackError {
46    fn from(error: csv::Error) -> BlackJackError {
47        BlackJackError::HeaderParseError(error)
48    }
49}
50
51impl From<Box<bincode::ErrorKind>> for BlackJackError {
52    fn from(error: Box<bincode::ErrorKind>) -> BlackJackError {
53        BlackJackError::SerializationDecodeError(error)
54    }
55}