1 // SPDX-License-Identifier: Apache-2.0 2 3 use alloc::string::{String, ToString}; 4 5 /// The error when serializing to/from a `Value` 6 #[derive(Debug)] 7 pub enum Error { 8 /// A custom error string produced by serde 9 Custom(String), 10 } 11 12 impl core::fmt::Display for Error { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result13 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 14 write!(f, "{:?}", self) 15 } 16 } 17 18 impl serde::de::StdError for Error {} 19 20 impl serde::de::Error for Error { 21 #[inline] custom<T: core::fmt::Display>(msg: T) -> Self22 fn custom<T: core::fmt::Display>(msg: T) -> Self { 23 Self::Custom(msg.to_string()) 24 } 25 } 26 27 impl serde::ser::Error for Error { 28 #[inline] custom<T: core::fmt::Display>(msg: T) -> Self29 fn custom<T: core::fmt::Display>(msg: T) -> Self { 30 Self::Custom(msg.to_string()) 31 } 32 } 33