Trait Upcast
pub trait Upcast<T: ?Sized>
A trait for type-safe generic upcasting.
⚠️ Unstable
This is part of the internal convert module, no
stability guarantees are provided. Use at your own risk. See its
documentation for more details.
Note
Upcast<T> has a blanket implementation for all types where T: UpcastFrom<Self>.
New upcast relationships should typically be defined by implementing FromUpcast
rather than Upcast directly, to avoid orphan rule issues.
Provided Methods
fn upcast(&self) -> &T where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = <Self as ErasableGeneric>::Repr>,Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system.
This enables proper nested conversions that obey subtyping rules, supporting strict API type checking.
The common pattern when passing a narrow type is to call
upcast()orupcast_into()to obtain the correct type for the function usage, while ensuring safe type checked usage.For example, if passing
Promise<Number>as an argument to a function wherePromise<JsValue>is expected, orFunction<JsValue>as an argument whereFunction<Number>is expected.This is a compile time conversion only by the nature of the erasable generics type system.
fn upcast_into(self) -> T where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = <Self as ErasableGeneric>::Repr>,Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system.
This enables proper nested conversions that obey subtyping rules, supporting strict API type checking.
The common pattern when passing a narrow type is to call
upcast()orupcast_into()to obtain the correct type for the function usage, while ensuring safe type checked usage.For example, if passing
Promise<Number>as an argument to a function wherePromise<JsValue>is expected, orFunctionArgs<JsValue>as an argument whereFunctionArgs<Number>is expected.This is a compile time conversion only by the nature of the erasable generics type system.
Implementors
impl<S, T> Upcast<T> for Clamped<T> where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for JsError where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for JsNullable<T> where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for JsOption<T> where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for JsStatic<T> where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for JsThreadLocal<T> where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for JsValue where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for Null where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for Parent<T> where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for S where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for ScopedClosure<'a, T> where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for Undefined where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for WasmRet<T> where T: UpcastFrom<S> + ?Sized, S: ?Sized,impl<S, T> Upcast<T> for WasmSlice where T: UpcastFrom<S> + ?Sized, S: ?Sized,