Trait DynCast

Source
pub trait DynCast
where Self: AsRef<Val> + Into<Val>,
{ // Required methods fn instanceof(val: &Val) -> bool; fn unchecked_from_val(v: Val) -> Self; fn unchecked_from_val_ref(v: &Val) -> &Self; // Provided methods fn has_type<T>(&self) -> bool where T: DynCast { ... } fn dyn_into<T>(self) -> Result<T, Self> where T: DynCast { ... } fn dyn_ref<T>(&self) -> Option<&T> where T: DynCast { ... } fn unchecked_into<T>(self) -> T where T: DynCast { ... } fn unchecked_ref<T>(&self) -> &T where T: DynCast { ... } fn is_instance_of<T>(&self) -> bool where T: DynCast { ... } fn is_type_of(val: &Val) -> bool { ... } }
Expand description

Trait analogous to wasm-bindgen::JsCast.

Automatically available on every wrapper that is:

  • holds a single emlite::Val
  • implements AsRef<Val> and Into<Val>

Required Methods§

Source

fn instanceof(val: &Val) -> bool

Implementation of val instanceof ThisType.

Source

fn unchecked_from_val(v: Val) -> Self

Zero-cost unchecked conversion from Val into Self.

Source

fn unchecked_from_val_ref(v: &Val) -> &Self

Zero-cost unchecked conversion from &Val into &Self.

Provided Methods§

Source

fn has_type<T>(&self) -> bool
where T: DynCast,

Source

fn dyn_into<T>(self) -> Result<T, Self>
where T: DynCast,

Source

fn dyn_ref<T>(&self) -> Option<&T>
where T: DynCast,

Source

fn unchecked_into<T>(self) -> T
where T: DynCast,

Source

fn unchecked_ref<T>(&self) -> &T
where T: DynCast,

Source

fn is_instance_of<T>(&self) -> bool
where T: DynCast,

Source

fn is_type_of(val: &Val) -> bool

Customisable brand check – defaults to instanceof.

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.

Implementors§