use std::error::Error;
use std::fmt;
use std::io;
#[derive(Debug)]
pub enum CommunicationError {
Io(io::Error),
NotInitialized,
}
impl Error for CommunicationError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
CommunicationError::Io(err) => Some(err),
_ => None,
}
}
}
impl fmt::Display for CommunicationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CommunicationError::Io(err) => write!(f, "I/O error: {}", err),
CommunicationError::NotInitialized => write!(f, "connection not initialized"),
}
}
}
impl From<io::Error> for CommunicationError {
fn from(err: io::Error) -> Self {
CommunicationError::Io(err)
}
}