use std::fmt;
#[derive(Debug)]
pub struct Error {
pub(crate) type_name: &'static str,
pub(crate) de: bool,
pub(crate) inner: SerializationError,
}
#[cfg(all(feature = "json", not(feature = "js")))]
type SerializationError = serde_json::Error;
#[cfg(feature = "js")]
type SerializationError = serde_wasm_bindgen::Error;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.de {
write!(
f,
"Failed to deserialize JsValue into type `{}`: {}",
self.type_name, self.inner
)
} else {
write!(
f,
"Failed to serialize type `{}` into JsValue: {}",
self.type_name, self.inner
)
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.inner)
}
}