pub trait Any: Any + Serialize + Deserialize {
    fn as_any(&self) -> &dyn Any;
    fn as_any_mut(&mut self) -> &mut dyn Any;
    fn into_any(self: Box<Self>) -> Box<dyn Any>;
}
Expand description

A convenience trait implemented on all (de)serializable implementors of std::any::Any.

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

Example

extern crate serde_json;
extern crate serde_traitobject as s;

use std::any::Any;

let erased: s::Box<dyn s::Any> = s::Box::new(String::from("hi there"));

let serialized = serde_json::to_string(&erased).unwrap();
let deserialized: s::Box<dyn s::Any> = serde_json::from_str(&serialized).unwrap();

let downcast: Box<String> = Box::<dyn Any>::downcast(deserialized.into_any()).unwrap();

println!("{}!", downcast);
// hi there!

Required Methods§

Convert to a &std::any::Any.

Convert to a &mut std::any::Any.

Convert to a std::boxed::Box<dyn std::any::Any>.

Implementations§

Convert into a std::boxed::Box<dyn std::any::Any + Send>.

Convert into a std::boxed::Box<dyn std::any::Any + Sync>.

Convert into a std::boxed::Box<dyn std::any::Any + Send + Sync>.

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
Serialize this value into the given Serde serializer. Read more
Serialize this value into the given Serde serializer. Read more

Implementors§