Trait serde::ser::Error
[−]
[src]
pub trait Error: Sized + Error { fn custom<T: Display>(msg: T) -> Self; }
Trait used by Serialize
implementations to generically construct errors
belonging to the Serializer
against which they are currently running.
Required Methods
fn custom<T: Display>(msg: T) -> Self
Raised when a Serialize
implementation encounters a general error
while serializing a type.
The message should not be capitalized and should not end with a period.
For example, a filesystem Path
may refuse to serialize itself if it
contains invalid UTF-8 data.
impl Serialize for Path { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer { match self.to_str() { Some(s) => s.serialize(serializer), None => Err(Error::custom("path contains invalid UTF-8 characters")), } } }