Trait IntoJsGeneric

pub trait IntoJsGeneric

Value conversion from a type into its canonical JsGeneric form.

This trait allows types to be converted into JsGeneric supported types, which are required to be erasably generic with JsValue.

The single associated type — rather than a free type parameter bounded by AsRef<T> — is what makes collection-style APIs infer annotation-free. Given an input A, there is exactly one A::JsCanon, so rustc never has to search across multiple AsRef impls to pick a target element type.

Implementations

Provided impls:

This trait is deliberately not blanket-implemented over all JsGeneric types: each implementor explicitly opts in, which leaves room for future wrapper types to pick a non-identity Self::JsCanon.

Example

use js_sys::{Array, Number};

let arr: Array<Number> = (0..10).map(Number::from).collect();

Associated Types

type JsCanon: JsGeneric;

The canonical JsGeneric form of this type.

Required Methods

fn to_js(self) -> Self::JsCanon

Produce the canonical JsGeneric value for self.

Implementors