use alloc::string::{String, ToString};
use core::fmt::{Debug, Display, Formatter, Result};
#[derive(Debug)]
pub struct SerdeError {
pub msg: String,
pub pos: u64,
}
impl SerdeError {
pub(crate) fn pos(mut self, pos: u64) -> Self {
self.pos = pos;
self
}
}
impl From<String> for SerdeError {
fn from(msg: String) -> Self {
Self { msg, pos: 0 }
}
}
impl Display for SerdeError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
Debug::fmt(self, f)
}
}
#[cfg(feature = "std")]
impl std::error::Error for SerdeError {}
impl serde::ser::Error for SerdeError {
fn custom<T: Display>(msg: T) -> Self {
Self::from(msg.to_string())
}
}
impl serde::de::Error for SerdeError {
fn custom<T: Display>(msg: T) -> Self {
Self::from(msg.to_string())
}
}