wasm_bindgen::convert

Trait WasmAbi

Source
pub trait WasmAbi {
    type Prim1: WasmPrimitive;
    type Prim2: WasmPrimitive;
    type Prim3: WasmPrimitive;
    type Prim4: WasmPrimitive;

    // Required methods
    fn split(self) -> (Self::Prim1, Self::Prim2, Self::Prim3, Self::Prim4);
    fn join(
        prim1: Self::Prim1,
        prim2: Self::Prim2,
        prim3: Self::Prim3,
        prim4: Self::Prim4,
    ) -> Self;
}
Expand description

A trait which represents types that can be passed across the Wasm ABI boundary, by being split into multiple Wasm primitive types.

Up to 4 primitives are supported; if you don’t want to use all of them, you can set the rest to (), which will cause them to be ignored.

You need to be careful how many primitives you use, however: Result<T, JsValue> uses up 2 primitives to store the error, and so it doesn’t work if T uses more than 2 primitives.

So, if you’re adding support for a type that needs 3 or more primitives and is able to be returned, you have to add another primitive here.

There’s already one type that uses 3 primitives: &mut [T]. However, it can’t be returned anyway, so it doesn’t matter that Result<&mut [T], JsValue> wouldn’t work.

§⚠️ Unstable

This is part of the internal convert module, no stability guarantees are provided. Use at your own risk. See its documentation for more details.

Required Associated Types§

Required Methods§

Source

fn split(self) -> (Self::Prim1, Self::Prim2, Self::Prim3, Self::Prim4)

Splits this type up into primitives to be sent over the ABI.

Source

fn join( prim1: Self::Prim1, prim2: Self::Prim2, prim3: Self::Prim3, prim4: Self::Prim4, ) -> Self

Reconstructs this type from primitives received over the ABI.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl WasmAbi for i128

Source§

type Prim1 = u64

Source§

type Prim2 = u64

Source§

type Prim3 = ()

Source§

type Prim4 = ()

Source§

fn split(self) -> (u64, u64, (), ())

Source§

fn join(low: u64, high: u64, _: (), _: ()) -> Self

Source§

impl WasmAbi for u128

Source§

type Prim1 = u64

Source§

type Prim2 = u64

Source§

type Prim3 = ()

Source§

type Prim4 = ()

Source§

fn split(self) -> (u64, u64, (), ())

Source§

fn join(low: u64, high: u64, _: (), _: ()) -> Self

Source§

impl<T: WasmAbi<Prim3 = (), Prim4 = ()>> WasmAbi for Result<T, u32>

Source§

type Prim3 = u32

If this Result is an Err, the error value.

Source§

type Prim4 = u32

Whether this Result is an Err.

Source§

type Prim1 = <T as WasmAbi>::Prim1

Source§

type Prim2 = <T as WasmAbi>::Prim2

Source§

fn split(self) -> (T::Prim1, T::Prim2, u32, u32)

Source§

fn join(prim1: T::Prim1, prim2: T::Prim2, err: u32, is_err: u32) -> Self

Source§

impl<T: WasmAbi<Prim4 = ()>> WasmAbi for Option<T>

Source§

type Prim1 = u32

Whether this Option is a Some value.

Source§

type Prim2 = <T as WasmAbi>::Prim1

Source§

type Prim3 = <T as WasmAbi>::Prim2

Source§

type Prim4 = <T as WasmAbi>::Prim3

Source§

fn split(self) -> (u32, T::Prim1, T::Prim2, T::Prim3)

Source§

fn join(is_some: u32, prim1: T::Prim1, prim2: T::Prim2, prim3: T::Prim3) -> Self

Implementors§