pub trait JsGeneric:
ErasableGeneric<Repr = JsValue>
+ UpcastFrom<Self>
+ Upcast<Self>
+ Upcast<JsValue>
+ 'static { }Expand description
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]
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.