use core::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Error {
Parse(ParseError),
Font(FontError),
Unsupported {
what: String,
},
Malformed {
what: String,
},
InvalidOption {
what: String,
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ParseError {
TrailingBackslash,
Unsupported(String),
Unknown(String),
Malformed(String),
UnmatchedDelimiter,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FontError {
InvalidFace,
MissingGlyph {
ch: char,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Parse(e) => write!(f, "{e}"),
Self::Font(e) => write!(f, "{e}"),
Self::Unsupported { what } => write!(f, "unsupported: {what}"),
Self::Malformed { what } => write!(f, "malformed: {what}"),
Self::InvalidOption { what } => write!(f, "invalid option: {what}"),
}
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::TrailingBackslash => f.write_str("trailing backslash"),
Self::Unsupported(s) => write!(f, "unsupported: {s}"),
Self::Unknown(s) => write!(f, "unknown command: {s}"),
Self::Malformed(s) => write!(f, "malformed: {s}"),
Self::UnmatchedDelimiter => f.write_str("unmatched delimiter"),
}
}
}
impl fmt::Display for FontError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidFace => f.write_str("invalid OpenType face"),
Self::MissingGlyph { ch } => write!(f, "missing glyph for {ch:?}"),
}
}
}
impl std::error::Error for Error {}
impl From<ParseError> for Error {
fn from(e: ParseError) -> Self {
Self::Parse(e)
}
}
impl From<FontError> for Error {
fn from(e: FontError) -> Self {
Self::Font(e)
}
}