use std::{
error::Error,
fmt::{self},
};
use serde::Deserialize;
#[derive(Deserialize)]
pub struct ServerStateError(pub String);
impl ServerStateError {
pub fn no_stream() -> ServerStateError {
ServerStateError(String::from(
"Stream has not been instanciated. Consider calling `server.open()`",
))
}
}
impl Error for ServerStateError {}
impl fmt::Display for ServerStateError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Bad Server state") }
}
impl fmt::Debug for ServerStateError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{{ file: {}, line: {} }}", file!(), line!()) }
}
impl From<rmp_serde::decode::Error> for ServerStateError {
fn from(error: rmp_serde::decode::Error) -> ServerStateError {
eprint!("{}", error);
ServerStateError(format!("{}", error))
}
}