Skip to main content

IntoJsGeneric

Trait IntoJsGeneric 

Source
pub trait IntoJsGeneric {
    type JsCanon: JsGeneric;

    // Required method
    fn to_js(self) -> Self::JsCanon;
}
Expand description

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:

  • JsValue in this crate.
  • Every #[wasm_bindgen]-imported type (identity — emitted by the macro).
  • Every generic js_sys container (Array<T>, Promise<T>, Set<T>, …) provides its own identity impl owned by js_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();

Required Associated Types§

Source

type JsCanon: JsGeneric

The canonical JsGeneric form of this type.

Required Methods§

Source

fn to_js(self) -> Self::JsCanon

Produce the canonical JsGeneric value for self.

Implementations on Foreign Types§

Source§

impl<T> IntoJsGeneric for &T
where T: IntoJsGeneric + Clone,

Implementors§

Source§

impl IntoJsGeneric for Collator

Source§

impl IntoJsGeneric for CollatorOptions

Source§

impl IntoJsGeneric for DateTimeFormat

Source§

impl IntoJsGeneric for DateTimeFormatOptions

Source§

impl IntoJsGeneric for DateTimeFormatPart

Source§

impl IntoJsGeneric for DateTimeRangeFormatPart

Source§

impl IntoJsGeneric for DisplayNames

Source§

impl IntoJsGeneric for DisplayNamesOptions

Source§

impl IntoJsGeneric for Duration

Source§

impl IntoJsGeneric for DurationFormat

Source§

impl IntoJsGeneric for DurationFormatOptions

Source§

impl IntoJsGeneric for DurationFormatPart

Source§

impl IntoJsGeneric for ListFormat

Source§

impl IntoJsGeneric for ListFormatOptions

Source§

impl IntoJsGeneric for ListFormatPart

Source§

impl IntoJsGeneric for Locale

Source§

impl IntoJsGeneric for LocaleMatcherOptions

Source§

impl IntoJsGeneric for NumberFormat

Source§

impl IntoJsGeneric for NumberFormatOptions

Source§

impl IntoJsGeneric for NumberFormatPart

Source§

impl IntoJsGeneric for NumberRangeFormatPart

Source§

impl IntoJsGeneric for PluralRules

Source§

impl IntoJsGeneric for PluralRulesOptions

Source§

impl IntoJsGeneric for RelativeTimeFormat

Source§

impl IntoJsGeneric for RelativeTimeFormatOptions

Source§

impl IntoJsGeneric for RelativeTimeFormatPart

Source§

impl IntoJsGeneric for ResolvedCollatorOptions

Source§

impl IntoJsGeneric for ResolvedDateTimeFormatOptions

Source§

impl IntoJsGeneric for ResolvedDisplayNamesOptions

Source§

impl IntoJsGeneric for ResolvedDurationFormatOptions

Source§

impl IntoJsGeneric for ResolvedListFormatOptions

Source§

impl IntoJsGeneric for ResolvedNumberFormatOptions

Source§

impl IntoJsGeneric for ResolvedPluralRulesOptions

Source§

impl IntoJsGeneric for ResolvedRelativeTimeFormatOptions

Source§

impl IntoJsGeneric for ResolvedSegmenterOptions

Source§

impl IntoJsGeneric for SegmentData

Source§

impl IntoJsGeneric for Segmenter

Source§

impl IntoJsGeneric for SegmenterOptions

Source§

impl IntoJsGeneric for Segments

Source§

impl IntoJsGeneric for TextInfo

Source§

impl IntoJsGeneric for WeekInfo

Source§

impl IntoJsGeneric for CompileError

Source§

impl IntoJsGeneric for Exception

Source§

impl IntoJsGeneric for Global

Source§

impl IntoJsGeneric for Instance

Source§

impl IntoJsGeneric for LinkError

Source§

impl IntoJsGeneric for Memory

Source§

impl IntoJsGeneric for Module

Source§

impl IntoJsGeneric for RuntimeError

Source§

impl IntoJsGeneric for Table

Source§

impl IntoJsGeneric for Tag
where Tag: JsGeneric,

Source§

impl IntoJsGeneric for JsValue

Source§

impl IntoJsGeneric for ArrayBuffer

Source§

impl IntoJsGeneric for ArrayBufferOptions

Source§

impl IntoJsGeneric for BigInt64Array

Source§

impl IntoJsGeneric for BigInt

Source§

impl IntoJsGeneric for BigUint64Array

Source§

impl IntoJsGeneric for Boolean

Source§

impl IntoJsGeneric for DataView

Source§

impl IntoJsGeneric for Date
where Date: JsGeneric,

Source§

impl IntoJsGeneric for Error

Source§

impl IntoJsGeneric for EvalError

Source§

impl IntoJsGeneric for Float16Array

Source§

impl IntoJsGeneric for Float32Array

Source§

impl IntoJsGeneric for Float64Array

Source§

impl IntoJsGeneric for Int8Array

Source§

impl IntoJsGeneric for Int16Array

Source§

impl IntoJsGeneric for Int32Array

Source§

impl IntoJsGeneric for JsString

Source§

impl IntoJsGeneric for Null
where Null: JsGeneric,

Source§

impl IntoJsGeneric for Number

Source§

impl IntoJsGeneric for Proxy

Source§

impl IntoJsGeneric for RangeError

Source§

impl IntoJsGeneric for ReferenceError

Source§

impl IntoJsGeneric for RegExp

Source§

impl IntoJsGeneric for RegExpMatchArray

Source§

impl IntoJsGeneric for SharedArrayBuffer

Source§

impl IntoJsGeneric for Symbol

Source§

impl IntoJsGeneric for SyntaxError

Source§

impl IntoJsGeneric for TypeError

Source§

impl IntoJsGeneric for Uint8Array

Source§

impl IntoJsGeneric for Uint8ClampedArray

Source§

impl IntoJsGeneric for Uint16Array

Source§

impl IntoJsGeneric for Uint32Array

Source§

impl IntoJsGeneric for Undefined

Source§

impl IntoJsGeneric for UriError

Source§

impl<K, V> IntoJsGeneric for Map<K, V>
where Map<K, V>: JsGeneric,

Source§

type JsCanon = Map<K, V>

Source§

impl<K, V> IntoJsGeneric for WeakMap<K, V>
where WeakMap<K, V>: JsGeneric,

Source§

impl<T> IntoJsGeneric for Array<T>
where Array<T>: JsGeneric,

Source§

impl<T> IntoJsGeneric for AsyncGenerator<T>

Source§

impl<T> IntoJsGeneric for AsyncIterator<T>

Source§

impl<T> IntoJsGeneric for Generator<T>
where Generator<T>: JsGeneric,

Source§

impl<T> IntoJsGeneric for Iterator<T>
where Iterator<T>: JsGeneric,

Source§

impl<T> IntoJsGeneric for IteratorNext<T>

Source§

impl<T> IntoJsGeneric for JsOption<T>
where JsOption<T>: JsGeneric,

Source§

impl<T> IntoJsGeneric for Object<T>
where Object<T>: JsGeneric,

Source§

impl<T> IntoJsGeneric for Promise<T>
where Promise<T>: JsGeneric,

Source§

impl<T> IntoJsGeneric for PromiseState<T>

Source§

impl<T> IntoJsGeneric for PropertyDescriptor<T>

Source§

impl<T> IntoJsGeneric for Set<T>
where Set<T>: JsGeneric,

Source§

impl<T> IntoJsGeneric for WeakRef<T>
where WeakRef<T>: JsGeneric,

Source§

impl<T> IntoJsGeneric for WeakSet<T>
where WeakSet<T>: JsGeneric,

Source§

impl<T: JsFunction> IntoJsGeneric for Function<T>
where Function<T>: JsGeneric,

Source§

impl<T: JsTuple> IntoJsGeneric for ArrayTuple<T>