Skip to main content

benday_core/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5    /// The spec parsed as JSON but is semantically invalid or unsupported.
6    Spec(String),
7    /// The data cannot support the requested encoding.
8    Data(String),
9}
10
11impl Error {
12    pub fn kind(&self) -> &'static str {
13        match self {
14            Error::Spec(_) => "spec",
15            Error::Data(_) => "data",
16        }
17    }
18}
19
20impl fmt::Display for Error {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Error::Spec(m) | Error::Data(m) => f.write_str(m),
24        }
25    }
26}
27
28impl std::error::Error for Error {}