pub trait Error: Error + Serialize + Deserialize { }
Expand description

A convenience trait implemented on all (de)serializable implementors of std::error::Error.

It can be made into a trait object which is then (de)serializable.

Example

#[macro_use] extern crate serde_derive;
extern crate serde_json;
extern crate serde_traitobject as s;

use std::fmt;

#[derive(Serialize,Deserialize,Debug)]
struct MyError(String);
impl fmt::Display for MyError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.0)
    }
}
impl std::error::Error for MyError {}

fn fallible() -> Result<(),s::Box<dyn s::Error>> {
    Err(Box::new(MyError(String::from("boxed error"))) as Box<dyn s::Error>)?
}

let serialized = serde_json::to_string(&fallible()).unwrap();
let deserialized: Result<(),s::Box<dyn s::Error>> = serde_json::from_str(&serialized).unwrap();

println!("{:?}", deserialized);
// Err(MyError("boxed error"))

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Deserialize this value from the given Serde deserializer. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Serialize this value into the given Serde serializer. Read more
Serialize this value into the given Serde serializer. Read more

Implementors§