Trait NativeWasmType

Source
pub trait NativeWasmType: Sized {
    type Abi: Copy + Debug;

    const WASM_TYPE: Type;

    // Required methods
    fn to_binary(self) -> i128;
    fn from_binary(binary: i128) -> Self;

    // Provided method
    fn to_value<T: WasmValueType>(self) -> Value<T> { ... }
}
Expand description

NativeWasmType represents a Wasm type that has a direct representation on the host (hence the “native” term).

It uses the Rust Type system to automatically detect the Wasm type associated with a native Rust type.

use wasmer_types::{NativeWasmType, Type};

let wasm_type = i32::WASM_TYPE;
assert_eq!(wasm_type, Type::I32);

Note: This strategy will be needed later to automatically detect the signature of a Rust function.

Required Associated Constants§

Source

const WASM_TYPE: Type

Type for this NativeWasmType.

Required Associated Types§

Source

type Abi: Copy + Debug

The ABI for this type (i32, i64, f32, f64)

Required Methods§

Source

fn to_binary(self) -> i128

Convert self to i128 binary representation.

Source

fn from_binary(binary: i128) -> Self

Convert to self from i128 binary representation.

Provided Methods§

Source

fn to_value<T: WasmValueType>(self) -> Value<T>

Convert self to a Value.

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 NativeWasmType for f32

Source§

const WASM_TYPE: Type = Type::F32

Source§

type Abi = f32

Source§

fn to_binary(self) -> i128

Source§

fn from_binary(bits: i128) -> Self

Source§

impl NativeWasmType for f64

Source§

const WASM_TYPE: Type = Type::F64

Source§

type Abi = f64

Source§

fn to_binary(self) -> i128

Source§

fn from_binary(bits: i128) -> Self

Source§

impl NativeWasmType for i32

Source§

const WASM_TYPE: Type = Type::I32

Source§

type Abi = i32

Source§

fn to_binary(self) -> i128

Source§

fn from_binary(bits: i128) -> Self

Source§

impl NativeWasmType for i64

Source§

const WASM_TYPE: Type = Type::I64

Source§

type Abi = i64

Source§

fn to_binary(self) -> i128

Source§

fn from_binary(bits: i128) -> Self

Source§

impl NativeWasmType for u128

Source§

const WASM_TYPE: Type = Type::V128

Source§

type Abi = u128

Source§

fn to_binary(self) -> i128

Source§

fn from_binary(bits: i128) -> Self

Implementors§