use serde_json;
use std::fmt;
use std::io;
#[derive(Debug)]
pub enum Error {
IoError(io::Error),
CannotDetermineTermsize,
NotJsonSerializable(serde_json::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::IoError(e) => write!(f, "{}", e),
Error::CannotDetermineTermsize => write!(f, "Cannot determine terminal size"),
Error::NotJsonSerializable(err) => write!(f, "Cannot serialize as JSON: {}", err),
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::IoError(err)
}
}
impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Error {
Error::NotJsonSerializable(err)
}
}
pub type Result<T> = std::result::Result<T, Error>;