[−][src]Macro xterm_js_sys::interface
Creates a Rust trait to match a particular JS interface.
In addition to the actual trait, this produces:
- glue that lets
'static
instances of the Rust trait be "turned into" instances of the JS interface - a blanket impl that implements the Rust trait for all
wasm-bindgen
produced types that extend the JS interface - an implementation of
IntoJsInterface
for all things that implement the Rust trait that's generated; this can be used to accept implementations of the Rust or implementations of the JS interface withimpl IntoJsInterface<JsInterfaceName>
Note: if you get an error about "unconditional recursion" when using this macro or an error about a trait not being in scope, it's because a method that you added to the trait doesn't exist on the underlying JS interface. Apologies for the cryptic error!
Also note that if you omit methods in the Rust interface you won't be
warned! You'll only find out when a JS user tries to call one of the methods
you missed at which point you'll get a runtime error 🙁 (we could use
JsCast::dyn_into
) instead of its unchecked counterpart but we don't
since that's not really all that much better (still a runtime error, but
you'll get it on convert rather than when you try to use the method in
question and you'll pay a performance penalty on every conversion).
Note that this currently requires that you have you IntoJsInterface
in
scope. This is because this trait must be defined in the crate where this
macro is called in order for the blanket impl that this macro produces for
IntoJsInterface
to type check. Rather than make it so that this macro only
works in this crate it'll instead work in other crates with the stipulation
that you need to mirror over the trait. Suboptimal, I know. And this
probably renders the little utility the IntoJsInterface
trait had moot.