[][src]Trait xterm_js_sys::ext::IntoJsInterface

pub trait IntoJsInterface<Interface: FromWasmAbi + IntoWasmAbi + JsCast> {
    fn to(self) -> Interface;
fn by_ref(&self) -> Interface; }
This is supported on feature="ext" only.

Represents a Rust type that satisfies a JS interface and can be turned into the concrete type that represents the JS interface.

See the disposable module for an example.

As mentioned in the xterm module docs we make a Rust trait dual for each JS interface (or the ones we want to make instances of, anyways). Ideally we'd be able to do something like this: trait RustTrait: IntoJsInterface<JsTrait>. The problem with that is that the impl of IntoJsInterface requires the impl of RustTrait; we need the functions that satisfy the interface to actually make the instance of the interface type.

So, instead we do the weird backwards thing that we do in disposable where the Rust trait (i.e. Disposable) ends up effectively having these same functions and then providing a blanket impl so that IntoJsInterface is impled for all things that impl the Rust trait.

It's unfortunate that we don't really have a way to encode that each Rust trait can have one (and only one) interface type dual. We encode this within the trait itself, but we can't seem to do this in a way that's generic over traits (not until we get HKTs anyways).

So it's unclear exactly where this trait would be useful. I guess it lets you be generic over the interface you're asking for? Something like this:

pub fn foo<I>(inst: impl IntoJsInterface<I>)
where
    I: FromWasmAbi + IntoWasmAbi + JsCast,
{
   inst.to();
}

Combined with AsRef you can do things like accept Rust implementations of interfaces that subclass some base class:

pub fn bar<I>(inst: impl IntoJsInterface<I>)
where
    I: FromWasmAbi + IntoWasmAbi + JsCast,
    I: AsRef<js_sys::Iterator>,
{
   inst.to();
}

But it's still unclear if/how this is useful.

Required methods

fn to(self) -> Interface

This is supported on feature="ext" only.

Convert to an instance of the JS interface type.

fn by_ref(&self) -> Interface

This is supported on feature="ext" only.

Produce an instance of the JS interface type without consuming the Rust instance.

For Rust impls of a trait this will probably require Self to implement Clone since as part of creating the instance the instance needs to be leaked (for methods to still work), but we'll leave that up to implementors.

Loading content...

Implementors

impl<X> IntoJsInterface<Disposable> for X where
    X: XtermDisposable,
    X: Clone + 'static, 
[src]

Anything that implements XtermDisposable (and is Clone + 'static) gets an implementation of IntoJsInterface<Disposable>.

fn to(self) -> Disposable[src]

This is supported on feature="ext" only.

Converts the XtermDisposable implementor into an instance of Disposable (the corresponding JS interface).

fn by_ref(&self) -> Disposable[src]

This is supported on feature="ext" only.

Converts the XtermDisposable implementor into an instance of Disposable (the corresponding JS interface) by reference.

impl<X> IntoJsInterface<TerminalAddon> for X where
    X: XtermAddon,
    X: Clone + 'static, 
[src]

Anything that implements XtermAddon (and is Clone + 'static) gets an implementation of IntoJsInterface<TerminalAddon>.

fn to(self) -> TerminalAddon[src]

This is supported on feature="ext" only.

Converts the XtermAddon implementor into an instance of TerminalAddon (the corresponding JS interface).

fn by_ref(&self) -> TerminalAddon[src]

This is supported on feature="ext" only.

Converts the XtermAddon implementor into an instance of TerminalAddon (the corresponding JS interface) by reference.

impl<X> IntoJsInterface<UnicodeVersionProvider> for X where
    X: XtermUnicodeVersionProvider,
    X: Clone + 'static, 
[src]

Anything that implements XtermUnicodeVersionProvider (and is Clone + 'static) gets an implementation of IntoJsInterface<UnicodeVersionProvider>.

fn to(self) -> UnicodeVersionProvider[src]

This is supported on feature="ext" only.

Converts the XtermUnicodeVersionProvider implementor into an instance of UnicodeVersionProvider (the corresponding JS interface).

fn by_ref(&self) -> UnicodeVersionProvider[src]

This is supported on feature="ext" only.

Converts the XtermUnicodeVersionProvider implementor into an instance of UnicodeVersionProvider (the corresponding JS interface) by reference.

Loading content...