Skip to main content

Cast

Enum Cast 

Source
pub enum Cast<'a, T>
where T: RefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>> + LongRefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>> + 'a,
{ Ref { anchor: <T as RefFromWasmAbi>::Anchor, }, OwnedRef { js_value: Option<JsValue>, anchor: Option<<T as RefFromWasmAbi>::Anchor>, }, LongRef { anchor: <T as LongRefFromWasmAbi>::Anchor, }, Value { value: Option<T>, }, _Unreachable(Infallible, &'a PhantomData<T>), }
Expand description

A wrapper for a Rust object that can be either a reference or a value. This wrapper is used to carry a Rust (WASM ABI) reference provided by wasm_bindgen, but at the same time allows creation of a temporary object that can be created by interpreting the source user-supplied data. Cast then provides Cast::as_ref() to obtain the internally held reference and Cast::into_owned() where the latter will consume the value or clone the reference.

Variants§

§

Ref

A borrowed reference to a Rust object obtained from the WASM ABI.

Fields

§anchor: <T as RefFromWasmAbi>::Anchor

Anchor keeping the borrowed reference alive.

§

OwnedRef

A reference that also owns (captures) the source JsValue keeping it alive.

Fields

§js_value: Option<JsValue>

The captured source JsValue backing the reference.

§anchor: Option<<T as RefFromWasmAbi>::Anchor>

Anchor keeping the borrowed reference alive.

§

LongRef

A long-lived reference to a Rust object obtained from the WASM ABI.

Fields

§anchor: <T as LongRefFromWasmAbi>::Anchor

Anchor keeping the long-lived reference alive.

§

Value

An owned value, typically created by interpreting user-supplied data.

Fields

§value: Option<T>

The owned value.

§

_Unreachable(Infallible, &'a PhantomData<T>)

Uninhabited variant carrying the lifetime parameter; never constructed.

Implementations§

Source§

impl<T> Cast<'_, T>
where T: LongRefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>> + RefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>> + Clone,

Source

pub fn into_owned(self) -> T

Consume the Cast and return the owned value. If the Cast holds a reference, it will be cloned.

Source

pub fn value(value: T) -> Cast<'_, T>

Construct a Cast::Value holding an owned value.

Trait Implementations§

Source§

impl<T> AsRef<T> for Cast<'_, T>
where T: LongRefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>> + RefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>>,

Source§

fn as_ref(&self) -> &T

Obtain a reference to the internally held value.

Source§

impl<T> Deref for Cast<'_, T>
where T: LongRefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>> + RefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>> + Deref,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Cast<'_, T> as Deref>::Target

Dereferences the value.
Source§

impl<T> Drop for Cast<'_, T>
where T: LongRefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>> + RefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'a, T> From<T> for Cast<'a, T>
where T: LongRefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>> + RefFromWasmAbi<Abi = WasmPtr<WasmRefCell<T>>>,

Cast T value (struct) into Cast<T>

Source§

fn from(value: T) -> Cast<'a, T>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Cast<'a, T>

§

impl<'a, T> RefUnwindSafe for Cast<'a, T>

§

impl<'a, T> Send for Cast<'a, T>

§

impl<'a, T> Sync for Cast<'a, T>

§

impl<'a, T> Unpin for Cast<'a, T>

§

impl<'a, T> UnsafeUnpin for Cast<'a, T>

§

impl<'a, T> UnwindSafe for Cast<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more