use std::fmt;
use std::io;
#[non_exhaustive]
#[derive(Debug)]
pub enum Error {
InvalidGlyphWidth(usize),
InvalidGridArea(),
Io(io::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
impl fmt::Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::InvalidGlyphWidth(w) => {
write!(fmt, "Invalid glyph width: {}", w)
}
Error::InvalidGridArea() => {
write!(fmt, "Invalid grid: all widgets must be rectangular")
}
Error::Io(ref err) => err.fmt(fmt),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Error::Io(ref err) => Some(err),
_ => None,
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::Io(err)
}
}