Trait windows_core::ComObjectInner
pub trait ComObjectInner: Sized {
type Outer: IUnknownImpl<Impl = Self>;
// Required method
fn into_object(self) -> ComObject<Self>;
}
Expand description
Identifies types that can be placed in ComObject
.
This trait links types that can be placed in ComObject
with the types generated by the
#[implement]
macro. The #[implement]
macro generates implementations of this trait.
The generated types contain the vtable layouts and refcount-related fields for the COM
object implementation.
This trait is an implementation detail of the Windows crates. User code should not deal directly with this trait.
This trait is sort of the reverse of [IUnknownImpl
]. This trait allows user code to use
ComObject<T>
instead of ComObject<T_Impl>
.
Required Associated Types§
type Outer: IUnknownImpl<Impl = Self>
type Outer: IUnknownImpl<Impl = Self>
The generated <foo>_Impl
type (aka the “boxed” type or “outer” type).
Required Methods§
fn into_object(self) -> ComObject<Self>
fn into_object(self) -> ComObject<Self>
Moves an instance of this type into a new ComObject box and returns it.
§Safety
It is important that safe Rust code never be able to acquire an owned instance of a
generated “outer” COM object type, e.g. <foo>_Impl
. This would be unsafe because the
<foo>_Impl
object contains a reference count field and provides methods that adjust
the reference count, and destroy the object when the reference count reaches zero.
Safe Rust code must only be able to interact with these values by accessing them via a
ComObject
reference. ComObject
handles adjusting reference counts and associates the
lifetime of a &<foo>_Impl
with the lifetime of the related ComObject
.
The #[implement]
macro generates the implementation of this into_object
method.
The generated into_object
method encapsulates the construction of the <foo>_Impl
object and immediately places it into the heap and returns a ComObject
reference to it.
This ensures that our requirement – that safe Rust code never own a <foo>_Impl
value
directly – is met.