pub struct Object<T: Class, ContainerT = Box<dyn Dyn>> { /* private fields */ }
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

Constructs an object from a container

Example:
#[subclass(DynamicObjectBase)]
struct MyObject;
 
let object = Object::<MyObject>::new(Box::new(MyObject {}));

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::>());

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);

Try to cast to ‘Cast’

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.