Trait Error

Source
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§

Source§

impl<'a> AsRef<dyn Error + 'a> for dyn Error + 'a

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> AsRef<dyn Error + Send + 'a> for dyn Error + Send + 'a

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'de> Deserialize<'de> for Box<dyn Error + 'static>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de> Deserialize<'de> for Box<dyn Error + Send + 'static>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a, E: Error + Serialize + Deserialize + 'a> From<E> for Box<dyn Error + 'a>

Source§

fn from(err: E) -> Self

Converts to this type from the input type.
Source§

impl Serialize for dyn Error

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Serialize for dyn Error + Send

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Implementors§

Source§

impl<T> Error for T
where T: Error + Serialize + Deserialize + ?Sized,