pub struct DynObject { /* private fields */ }
Expand description
Typed-erased version of
Object
Implementations§
Source§impl DynObject
impl DynObject
Sourcepub fn new<T: Object + Send + Sync + 'static>(v: Arc<T>) -> Self
pub fn new<T: Object + Send + Sync + 'static>(v: Arc<T>) -> Self
Returns a new boxed, type-erased
Object
.
Sourcepub fn repr(&self) -> ObjectRepr
pub fn repr(&self) -> ObjectRepr
Calls
Object::repr
on the underlying boxed value.
Sourcepub fn get_value(&self, key: &Value) -> Option<Value>
pub fn get_value(&self, key: &Value) -> Option<Value>
Calls
Object::get_value
on the underlying boxed value.
Sourcepub fn enumerate(&self) -> Enumerator
pub fn enumerate(&self) -> Enumerator
Calls
Object::enumerate
on the underlying boxed value.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Calls
Object::is_empty
on the underlying boxed value.
Sourcepub fn len(&self) -> Option<usize>
pub fn len(&self) -> Option<usize>
Calls
Object::len
on the underlying boxed value.
Sourcepub fn call(
&self,
state: &State<'_, '_>,
args: &[Value],
) -> Result<Value, Error>
pub fn call( &self, state: &State<'_, '_>, args: &[Value], ) -> Result<Value, Error>
Calls
Object::call
on the underlying boxed value.
Sourcepub fn call_method(
&self,
state: &State<'_, '_>,
method: &str,
args: &[Value],
) -> Result<Value, Error>
pub fn call_method( &self, state: &State<'_, '_>, method: &str, args: &[Value], ) -> Result<Value, Error>
Calls
Object::call_method
on the underlying boxed value.
Sourcepub fn render(&self, f: &mut Formatter<'_>) -> Result
pub fn render(&self, f: &mut Formatter<'_>) -> Result
Calls
Object::render
on the underlying boxed value.
Sourcepub fn downcast_ref<T: 'static>(&self) -> Option<&T>
pub fn downcast_ref<T: 'static>(&self) -> Option<&T>
Downcast to T
if the boxed value holds a T
.
This is basically the “reverse” of Value::from_object
.
§Example
use std::fmt;
#[derive(Debug)]
struct Thing {
id: usize,
}
impl Object for Thing {}
let x_value = Value::from_object(Thing { id: 42 });
let value_as_obj = x_value.as_object().unwrap();
let thing = value_as_obj.downcast_ref::<Thing>().unwrap();
assert_eq!(thing.id, 42);
Sourcepub fn downcast<T: 'static>(&self) -> Option<Arc<T>>
pub fn downcast<T: 'static>(&self) -> Option<Arc<T>>
Downcast to T
if the boxed value holds a T
.
For details see downcast_ref
.
Sourcepub fn is<T: 'static>(&self) -> bool
pub fn is<T: 'static>(&self) -> bool
Checks if the boxed value is a T
.
For details see downcast_ref
.
Trait Implementations§
impl Send for DynObject
impl Sync for DynObject
Auto Trait Implementations§
impl Freeze for DynObject
impl RefUnwindSafe for DynObject
impl Unpin for DynObject
impl UnwindSafe for DynObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more