pub trait CppSubclassSelfOwned<CppPeer: CppSubclassCppPeer>: CppSubclass<CppPeer> {
// Provided methods
fn new_self_owned(me: Self) -> Rc<RefCell<Self>> { ... }
fn delete_self(&self) { ... }
}
Expand description
Trait to be implemented by subclasses which are self-owned, i.e. not owned externally by either Rust or C++ code, and thus need the ability to delete themselves when some virtual function is called.
Provided Methods§
Sourcefn new_self_owned(me: Self) -> Rc<RefCell<Self>>
fn new_self_owned(me: Self) -> Rc<RefCell<Self>>
Creates a new instance of this subclass which owns itself.
This is useful
for observers (etc.) which self-register to listen to events.
If an event occurs which would cause this to want to unregister,
use CppSubclassSelfOwned::delete_self
.
The return value may be useful to register this, etc. but can ultimately
be discarded without destroying this object.
Sourcefn delete_self(&self)
fn delete_self(&self)
Relinquishes ownership from the C++ side. If there are no outstanding references from the Rust side, this will result in the destruction of this subclass instance.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.