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:
JsValuein this crate.- Every
#[wasm_bindgen]-imported type (identity — emitted by the macro). - Every generic
js_syscontainer (Array<T>,Promise<T>,Set<T>, …) provides its own identity impl owned byjs_sys. - References to cloneable implementors, so borrowed iteration can still produce owned JS-generic values.
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
JsGenericform of this type.
Required Methods
fn to_js(self) -> Self::JsCanonProduce the canonical
JsGenericvalue forself.
Implementors
impl IntoJsGeneric for JsValueimpl IntoJsGeneric for Null where Null: JsGeneric,impl IntoJsGeneric for Undefined where Undefined: JsGeneric,impl<T> IntoJsGeneric for JsNullable<T> where JsNullable<T>: JsGeneric,impl<T> IntoJsGeneric for JsOption<T> where JsOption<T>: JsGeneric,impl<T: IntoJsGeneric + Clone> IntoJsGeneric for &T