macro_rules! js_deserializable {
($kind:tt) => { ... };
(impl< $($impl_arg:tt),* > for $kind:ty where $($bounds:tt)*) => { ... };
(impl< $($impl_arg:tt),* > for $kind:ty) => { ... };
}
Expand description
A macro which makes it possible to convert an instance of a given type
implementing Serde’s Deserialize
into a Value using
TryInto.
For types defined outside of your crate you can also use the Serde newtype to make them deserializable indirectly.
§Examples
#[derive(Deserialize, Debug)]
struct Person {
name: String,
age: i32
}
js_deserializable!( Person );
let value = js! {
return {
name: "Bob",
age: 33
};
};
let structure: Person = value.try_into().unwrap();
assert_eq!( structure.name, "Bob" );
assert_eq!( structure.age, 33 );
This macro also accepts generics just as the js_serializable! does.