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§
Sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Convert the Rust type which implements NativeObject to a &dyn Any.
Sourcefn as_mut_any(&mut self) -> &mut dyn Any
fn as_mut_any(&mut self) -> &mut dyn Any
Convert the Rust type which implements NativeObject to a &mut dyn Any.
Sourcefn type_name_of_value(&self) -> &'static str
fn type_name_of_value(&self) -> &'static str
Gets the type name of the value.
Implementations§
Source§impl dyn NativeObject
impl dyn NativeObject
Sourcepub fn is<T: NativeObject>(&self) -> bool
pub fn is<T: NativeObject>(&self) -> bool
Returns true if the inner type is the same as T.
Sourcepub fn downcast_ref<T: NativeObject>(&self) -> Option<&T>
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.
Sourcepub fn downcast_mut<T: NativeObject>(&mut self) -> Option<&mut T>
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.
Sourcepub unsafe fn downcast_ref_unchecked<T: NativeObject>(&self) -> &T
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.
Sourcepub unsafe fn downcast_mut_unchecked<T: NativeObject>(&mut self) -> &mut T
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.