Crates.io | stdweb-derive |
lib.rs | stdweb-derive |
version | 0.5.3 |
source | src |
created_at | 2018-02-21 19:30:48.62776 |
updated_at | 2019-10-10 19:25:58.50403 |
description | Derive macros for the `stdweb` crate |
homepage | https://github.com/koute/stdweb |
repository | https://github.com/koute/stdweb |
max_upload_size | |
id | 52252 |
size | 16,918 |
stdweb
crateThis crate currently defines a derive macro for stdweb
which allows you to define custom reference types outside
of stdweb
.
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} ); );