Trait boa_engine::object::NativeObject
source · 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.