[−][src]Derive Macro stdweb_derive::ReferenceType
#[derive(ReferenceType)] { // Attributes available to this derive: #[reference] }
A derive macro for defining custom reference types.
For example:
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)] #[reference(instance_of = "Error")] pub struct Error( Reference ); #[derive(Clone, Debug, PartialEq, Eq, ReferenceType)] #[reference(instance_of = "TypeError")] #[reference(subclass_of(Error))] pub struct TypeError( Reference );
And then you can do:
// You can use `try_into` to cast a `Value` to your type. let error: TypeError = js!( return new TypeError(); ).try_into().unwrap(); // You can also pass your type freely into the `js!` macro: js!( console.log( @{error} ); );