serde_test2 2.0.0

Token De/Serializer for testing De/Serialize implementations
Documentation
use alloc::string::{String, ToString as _};
use core::fmt::{self, Display};
#[cfg(feature = "std")]
use std::error;

use serde_core::{de, ser};

#[derive(Clone, Debug)]
pub(crate) struct Error {
    msg: String,
}

impl ser::Error for Error {
    fn custom<T: Display>(msg: T) -> Self {
        Self {
            msg: msg.to_string(),
        }
    }
}

impl de::Error for Error {
    fn custom<T: Display>(msg: T) -> Self {
        Self {
            msg: msg.to_string(),
        }
    }
}

impl fmt::Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str(&self.msg)
    }
}

#[cfg(feature = "std")]
impl error::Error for Error {}

impl PartialEq<str> for Error {
    fn eq(&self, other: &str) -> bool {
        self.msg == other
    }
}