#[cfg(feature = "json")]
use serde_json;
use std::{error, fmt, io};
use crate::network;
#[derive(Debug)]
pub enum Error {
#[cfg(feature = "json")]
Serde(serde_json::Error),
Io(io::Error),
CGE(network::Error),
RecurrentState(network::MismatchedLengthsError),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
#[cfg(feature = "json")]
Self::Serde(e) => write!(f, "de/serialization error: {}", e),
Self::Io(e) => write!(f, "io error: {}", e),
Self::CGE(e) => write!(f, "network error: {}", e),
Self::RecurrentState(e) => write!(f, "failed to set recurrent state: {}", e),
}
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
#[cfg(feature = "json")]
Self::Serde(e) => Some(e),
Self::Io(e) => Some(e),
Self::CGE(e) => Some(e),
Self::RecurrentState(e) => Some(e),
}
}
}
#[cfg(feature = "json")]
impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Self::Serde(e)
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Self::Io(e)
}
}
impl From<network::Error> for Error {
fn from(e: network::Error) -> Self {
Self::CGE(e)
}
}
impl From<network::MismatchedLengthsError> for Error {
fn from(e: network::MismatchedLengthsError) -> Self {
Self::RecurrentState(e)
}
}