use super::super::{normal::*, *};
use {
serde::de,
std::{fmt, io},
thiserror::*,
};
#[derive(Debug, Error)]
pub enum DeserializeError {
#[error("unsupported format: {0:?}")]
UnsupportedFormat(Format),
#[error("incompatible type: {0}")]
IncompatibleType(&'static str),
#[error("incompatible variant: {0}")]
IncompatibleVariant(String),
#[error("no more items")]
NoMoreItems,
#[error("not supported: {0}")]
NotSupported(&'static str),
#[error("read: {0}")]
Read(#[from] parse::ParseError),
#[error("I/O: {0}")]
IO(#[from] io::Error),
#[error("custom: {0}")]
Custom(String),
}
impl DeserializeError {
pub fn incompatible_type<AnnotatedT>(variant: &Variant<AnnotatedT>) -> DeserializeError {
Self::IncompatibleType(variant.type_name())
}
pub fn incompatible_variant<AnnotatedT>(variant: &Variant<AnnotatedT>) -> DeserializeError {
Self::IncompatibleVariant(format!("{}", variant))
}
}
impl de::Error for DeserializeError {
fn custom<DisplayT>(message: DisplayT) -> Self
where
DisplayT: fmt::Display,
{
DeserializeError::Custom(message.to_string())
}
}