JsGeneric in js_sys - Rust (original) (raw)

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:

§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 implementErasableGeneric<Repr = JsValue>, including:

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.