rusty_data/
error.rs

1//! Module for errors within the rusty-data crate.
2
3use std::fmt;
4use std::error::Error;
5
6/// Errors related to Data functions.
7#[derive(Debug)]
8pub enum DataError {
9    /// An error for failed data casting.
10    DataCastError,
11    /// An error reported when the data state was invalid for the operation.
12    InvalidStateError,
13}
14
15impl fmt::Display for DataError {
16    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17        match self {
18            &DataError::DataCastError => write!(f, "DataCastError"),
19            &DataError::InvalidStateError => write!(f, "InvalidStateError"),
20        }
21    }
22}
23
24impl Error for DataError {
25    fn description(&self) -> &str {
26        match self {
27            &DataError::DataCastError => "Failed to cast data.",
28            &DataError::InvalidStateError => "Operation was not valid for state of object.",
29        }
30    }
31}