Trait JsGeneric
pub trait JsGeneric: ErasableGeneric<Repr = JsValue> + UpcastFrom<Self> + Upcast<Self> + Upcast<JsValue> + JsCast + 'static
A convenience trait for types that erase to JsValue.
This is a shorthand for ErasableGeneric<Repr = JsValue>, used as a bound
on generic parameters that must be representable as JavaScript values.
When to Use
Use JsGeneric as a trait bound when you need a generic type that:
- Can be passed to/from JavaScript
- Is type-erased to
JsValueat the FFI boundary
Examples
use wasm_bindgen::JsGeneric;
fn process_js_values<T: JsGeneric>(items: &[T]) {
// T can be any JS-compatible type
}
Implementors
This trait is automatically implemented for all types that implement
ErasableGeneric<Repr = JsValue>, including:
- All
js_systypes (Object,Array,Function, etc.) JsValueitself- Custom types imported via
#[wasm_bindgen]
Implementors
impl<T> JsGeneric for JsNullable<T> where T: ErasableGeneric<Repr = JsValue> + UpcastFrom<T> + Upcast<JsValue> + JsCast + 'static,impl<T> JsGeneric for JsOption<T> where T: ErasableGeneric<Repr = JsValue> + UpcastFrom<T> + Upcast<JsValue> + JsCast + 'static,impl<T> JsGeneric for JsValue where T: ErasableGeneric<Repr = JsValue> + UpcastFrom<T> + Upcast<JsValue> + JsCast + 'static,impl<T> JsGeneric for Null where T: ErasableGeneric<Repr = JsValue> + UpcastFrom<T> + Upcast<JsValue> + JsCast + 'static,impl<T> JsGeneric for Undefined where T: ErasableGeneric<Repr = JsValue> + UpcastFrom<T> + Upcast<JsValue> + JsCast + 'static,impl<T: ErasableGeneric<Repr = JsValue> + UpcastFrom<T> + Upcast<JsValue> + JsCast + 'static> JsGeneric for T