pub trait NativeObject: Any + Trace + JsData {
    // Required methods
    fn as_any(&self) -> &dyn Any;
    fn as_mut_any(&mut self) -> &mut dyn Any;
    fn type_name_of_value(&self) -> &'static str;
}
Expand description

This trait allows Rust types to be passed around as objects.

This is automatically implemented when a type implements Any, Trace, and JsData.

Required Methods§

source

fn as_any(&self) -> &dyn Any

Convert the Rust type which implements NativeObject to a &dyn Any.

source

fn as_mut_any(&mut self) -> &mut dyn Any

Convert the Rust type which implements NativeObject to a &mut dyn Any.

source

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

Gets the type name of the value.

Implementations§

source§

impl dyn NativeObject

source

pub fn is<T: NativeObject>(&self) -> bool

Returns true if the inner type is the same as T.

source

pub fn downcast_ref<T: NativeObject>(&self) -> Option<&T>

Returns some reference to the inner value if it is of type T, or None if it isn’t.

source

pub fn downcast_mut<T: NativeObject>(&mut self) -> Option<&mut T>

Returns some mutable reference to the inner value if it is of type T, or None if it isn’t.

source

pub unsafe fn downcast_ref_unchecked<T: NativeObject>(&self) -> &T

Returns a reference to the inner value as type dyn T.

§Safety

The contained value must be of type T. Calling this method with the incorrect type is undefined behavior.

source

pub unsafe fn downcast_mut_unchecked<T: NativeObject>(&mut self) -> &mut T

Returns a mutable reference to the inner value as type dyn T.

§Safety

The contained value must be of type T. Calling this method with the incorrect type is undefined behavior.

Implementors§