Skip to main content

VectorRefIntoWasmAbi

Trait VectorRefIntoWasmAbi 

Source
pub trait VectorRefIntoWasmAbi {
    // Required method
    fn slice_into_abi(slice: &[Self]) -> WasmSlice
       where Self: Sized;

    // Provided method
    fn slice_none() -> WasmSlice
       where Self: Sized { ... }
}
Expand description

Internal trait used by the slice_to_array macro codegen.

Produces the wire representation JS observes when an outgoing &[T] argument is rendered as a plain Array. There are two impl shapes, neither of which requires T: Clone:

  • For primitive numeric T (u8, i32, f64, …) the wire is a borrow of the slice memory directly — no allocation, no copy. The JS-side shim performs Array.from(typedArrayView) to materialise the JS Array and never frees the buffer.
  • For everything else (String, JsValue, imported types, exported types) the wire is a freshly allocated Box<[u32]> of externref indices — one per element, constructed via &T -> JsValue (which for handle-shaped types is a refcount bump on the existing JS slot, and for String / value-shaped types creates a fresh JS value). The JS-side shim reads the indices into a JS Array and frees the index buffer.

Both shapes carry the same WasmSlice (ptr + len) on the wire. The cli-support side picks the right JS shim based on the element VectorKind recovered from the descriptor.

Not user-facing: users opt in via #[wasm_bindgen(slice_to_array)] on an imported function or extern "C" block.

Required Methods§

Source

fn slice_into_abi(slice: &[Self]) -> WasmSlice
where Self: Sized,

Construct the wire representation for Some(slice). The returned WasmSlice is either a borrow of the input slice (primitive case) or a buffer JS owns and frees (handle-shaped case).

Provided Methods§

Source

fn slice_none() -> WasmSlice
where Self: Sized,

Wire representation for None (used by Option<&[T]>). A null WasmSlice (ptr == 0) is the convention shared with every other vector-like ABI in the crate.

Implementations on Foreign Types§

Source§

impl VectorRefIntoWasmAbi for f32

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for f64

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for i8

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for i16

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for i32

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for i64

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for isize

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for u8

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for u16

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for u32

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for u64

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Source§

impl VectorRefIntoWasmAbi for usize

Source§

fn slice_into_abi(slice: &[Self]) -> WasmSlice

Implementors§

Source§

impl<T> VectorRefIntoWasmAbi for T
where for<'a> &'a T: Into<JsValue>,