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 performsArray.from(typedArrayView)to materialise the JSArrayand never frees the buffer. - For everything else (
String,JsValue, imported types, exported types) the wire is a freshly allocatedBox<[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 forString/ value-shaped types creates a fresh JS value). The JS-side shim reads the indices into a JSArrayand 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§
Sourcefn slice_into_abi(slice: &[Self]) -> WasmSlicewhere
Self: Sized,
fn slice_into_abi(slice: &[Self]) -> WasmSlicewhere
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§
Sourcefn slice_none() -> WasmSlicewhere
Self: Sized,
fn slice_none() -> WasmSlicewhere
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.