stdweb-derive

Crates.iostdweb-derive
lib.rsstdweb-derive
version0.5.3
sourcesrc
created_at2018-02-21 19:30:48.62776
updated_at2019-10-10 19:25:58.50403
descriptionDerive macros for the `stdweb` crate
homepagehttps://github.com/koute/stdweb
repositoryhttps://github.com/koute/stdweb
max_upload_size
id52252
size16,918
Koute (koute)

documentation

https://docs.rs/stdweb/*/stdweb/

README

Derive macros for the stdweb crate

This 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} ); );
Commit count: 530

cargo fmt