Struct dynamic_object::Object
source · [−]Expand description
An object The ContainerT generic parameter controls the container of the object’s pointer Dereference it (*object) to get the inner class
Implementations
sourceimpl<T: Class, ContainerT> Object<T, ContainerT>
impl<T: Class, ContainerT> Object<T, ContainerT>
sourcepub fn new(object: ContainerT) -> Self
pub fn new(object: ContainerT) -> Self
Constructs an object from a container
Example:
#[subclass(DynamicObjectBase)]
struct MyObject;
let object = Object::<MyObject>::new(Box::new(MyObject {}));
sourcepub fn isa<Other: Class>(&self) -> bool
pub fn isa<Other: Class>(&self) -> bool
Check if the object is a child of Other or is type Other
Example:
#[subclass(DynamicObjectBase)]
struct MyObject;
let object = Object::<MyObject>::new(Box::new(MyObject {}));
assert!(object.isa::<DynamicObjectBase::>());
sourcepub fn cast<Cast: Class>(self) -> Object<Cast, ContainerT>
pub fn cast<Cast: Class>(self) -> Object<Cast, ContainerT>
Cast to type ‘Cast’ panic if ‘self’ does not inherit from ‘Cast’/ is not ‘Cast’
Example:
#[subclass(DynamicObjectBase)]
struct Class {
value: u32,
foo: u32
}
#[subclass(Class, parent)]
struct Derived {
field: u32,
parent: Class,
}
let object = Derived {
parent: Class {
value: 548389,
foo: 72840548
},
field: 2153746,
};
let object = Object::<Derived>::new(Box::new(object));
assert!(object.field == 2153746);
assert!(object.parent.value == 548389);
assert!(object.parent.foo == 72840548);
let object = object.cast::<Class>();
assert!(object.value == 548389);
assert!(object.foo == 72840548);
let object = object.cast::<Derived>();
assert!(object.field == 2153746);
assert!(object.parent.value == 548389);
assert!(object.parent.foo == 72840548);
Trait Implementations
impl<T: Class, Container: Copy> Copy for Object<T, Container>
Auto Trait Implementations
impl<T, ContainerT> RefUnwindSafe for Object<T, ContainerT> where
ContainerT: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, ContainerT> Send for Object<T, ContainerT> where
ContainerT: Send,
T: Send,
impl<T, ContainerT> Sync for Object<T, ContainerT> where
ContainerT: Sync,
T: Sync,
impl<T, ContainerT> Unpin for Object<T, ContainerT> where
ContainerT: Unpin,
T: Unpin,
impl<T, ContainerT> UnwindSafe for Object<T, ContainerT> where
ContainerT: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more