// SPDX-License-Identifier: Apache-2.0 use alloc::string::{String, ToString}; use core::fmt::{Debug, Display, Formatter, Result}; use serde::ser::{Error as SerError, StdError}; /// An error occurred during serialization #[derive(Debug)] pub enum Error { /// An error occurred while writing bytes /// /// Contains the underlying error reaturned while writing. Io(T), /// An error indicating a value that cannot be serialized /// /// Contains a description of the problem. Value(String), } impl From for Error { #[inline] fn from(value: T) -> Self { Error::Io(value) } } impl Display for Error { #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "{:?}", self) } } impl StdError for Error {} impl SerError for Error { fn custom(msg: U) -> Self { Error::Value(msg.to_string()) } }