Macro stdweb::js_serializable
[−]
[src]
macro_rules! js_serializable { ($kind:tt) => { ... }; (impl< $($impl_arg:tt),* > for $kind:ty where $($bounds:tt)*) => { ... }; (impl< $($impl_arg:tt),* > for $kind:ty) => { ... }; }
A macro which makes it possible to pass an instance of a given type
implementing Serde's Serialize
into the js! macro.
For types defined outside of your crate you can also use the Serde newtype to make them serializable indirectly.
Examples
#[derive(Serialize, Debug)] struct Person { name: String, age: i32 } js_serializable!( Person ); let person = Person { name: "Bob".to_owned(), age: 33 }; js! { var person = @{person}; console.log( person.name + " is " + person.age + " years old." ); };
This macro also accepts generics:
trait Foobar {} #[derive(Serialize)] struct Wrapper< 'a, T: Serialize + 'a >( &'a T ); js_serializable!( impl< 'a, T > for Wrapper< 'a, T > where T: Serialize + Foobar );