|
|
|
@ -12,9 +12,43 @@ pub enum ErrorKind
|
|
|
|
|
Json(serde_json::Error),
|
|
|
|
|
Cbor(serde_cbor::Error),
|
|
|
|
|
Lexpr(serde_lexpr::Error),
|
|
|
|
|
/// Unknown format ID
|
|
|
|
|
UnknownFormat(u32),
|
|
|
|
|
/// Unknown error
|
|
|
|
|
Unknown,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl error::Error for ErrorKind
|
|
|
|
|
{
|
|
|
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
|
|
|
Some(match &self {
|
|
|
|
|
ErrorKind::IO(i) => i,
|
|
|
|
|
ErrorKind::Json(i) => i,
|
|
|
|
|
ErrorKind::Cbor(i) => i,
|
|
|
|
|
ErrorKind::Lexpr(i) => i,
|
|
|
|
|
_ => return None,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl fmt::Display for ErrorKind
|
|
|
|
|
{
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
|
|
|
{
|
|
|
|
|
match self {
|
|
|
|
|
Self::IO(_) => write!(f, "io"),
|
|
|
|
|
|
|
|
|
|
Self::Json(_) => write!(f, "conv json"),
|
|
|
|
|
Self::Cbor(_) => write!(f, "conv cbor"),
|
|
|
|
|
Self::Lexpr(_) => write!(f, "conv lexpr"),
|
|
|
|
|
|
|
|
|
|
Self::UnknownFormat(fmt) => write!(f, "unknown format ID: {}", fmt),
|
|
|
|
|
|
|
|
|
|
_ => write!(f, "unknown error")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<io::Error> for ErrorKind
|
|
|
|
|
{
|
|
|
|
|
fn from(from: io::Error) -> Self
|
|
|
|
@ -92,14 +126,9 @@ impl Error
|
|
|
|
|
|
|
|
|
|
impl error::Error for Error
|
|
|
|
|
{
|
|
|
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
|
|
|
Some(match self.0.as_ref() {
|
|
|
|
|
ErrorKind::IO(i) => i,
|
|
|
|
|
ErrorKind::Json(i) => i,
|
|
|
|
|
ErrorKind::Cbor(i) => i,
|
|
|
|
|
ErrorKind::Lexpr(i) => i,
|
|
|
|
|
_ => return None,
|
|
|
|
|
})
|
|
|
|
|
#[inline] fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
|
|
|
use error::Error;
|
|
|
|
|
self.0.source()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|