pub unsafe trait Interface: Sized + Clone {
const IID: GUID;
// Provided methods
fn as_raw(&self) -> *mut c_void { ... }
fn into_raw(self) -> *mut c_void { ... }
unsafe fn from_raw(raw: *mut c_void) -> Self { ... }
unsafe fn from_raw_borrowed(raw: &*mut c_void) -> Option<&Self> { ... }
fn cast<T>(&self) -> Result<T, Error>
where T: Interface { ... }
fn cast_to_any<T>(&self) -> Result<&(dyn Any + 'static), Error>
where T: ComObjectInner,
<T as ComObjectInner>::Outer: Any + 'static + IUnknownImpl<Impl = T> { ... }
fn is_object<T>(&self) -> bool
where T: ComObjectInner,
<T as ComObjectInner>::Outer: Any + 'static + IUnknownImpl<Impl = T> { ... }
fn cast_object_ref<T>(&self) -> Result<&<T as ComObjectInner>::Outer, Error>
where T: ComObjectInner,
<T as ComObjectInner>::Outer: Any + 'static + IUnknownImpl<Impl = T> { ... }
fn cast_object<T>(&self) -> Result<ComObject<T>, Error>
where T: ComObjectInner,
<T as ComObjectInner>::Outer: Any + 'static + IUnknownImpl<Impl = T> { ... }
fn downgrade(&self) -> Result<Weak<Self>, Error> { ... }
unsafe fn query(
&self,
iid: *const GUID,
interface: *mut *mut c_void,
) -> HRESULT { ... }
fn to_ref(&self) -> InterfaceRef<'_, Self> { ... }
}Expand description
Provides low-level access to a COM interface vtable.
§Safety
Implementors must be transparent wrappers over an owned COM interface pointer. Vtable and
IID must describe that interface, and cloning the wrapper must retain the COM reference.
Required Associated Constants§
Provided Methods§
Sourcefn into_raw(self) -> *mut c_void
fn into_raw(self) -> *mut c_void
Transfers ownership of the COM interface pointer to the caller.
Sourceunsafe fn from_raw(raw: *mut c_void) -> Self
unsafe fn from_raw(raw: *mut c_void) -> Self
Takes ownership of a COM interface pointer.
§Safety
raw must be owned and point to the vtable for Self, beginning with IUnknown.
Sourceunsafe fn from_raw_borrowed(raw: &*mut c_void) -> Option<&Self>
unsafe fn from_raw_borrowed(raw: &*mut c_void) -> Option<&Self>
Borrows a COM interface pointer.
§Safety
raw must remain valid and point to the vtable for Self, beginning with IUnknown.
Sourcefn cast<T>(&self) -> Result<T, Error>where
T: Interface,
fn cast<T>(&self) -> Result<T, Error>where
T: Interface,
Queries the object for another interface.
Sourcefn cast_to_any<T>(&self) -> Result<&(dyn Any + 'static), Error>
fn cast_to_any<T>(&self) -> Result<&(dyn Any + 'static), Error>
Returns the generated outer Rust implementation as [&dyn Any].
Applications should use
Interface::cast_object_ref or Interface::cast_object instead.
The reference points to the generated outer type, such as MyApp_Impl, not MyApp.
Returns Err(E_NOINTERFACE) if the object is not a Rust object, not T, or contains
non-static lifetimes.
§Safety
This uses a private QueryInterface protocol identified by DYNAMIC_CAST_IID. The
implementation writes a two-pointer &dyn Any, not a COM interface pointer, to the output.
The protocol does not call AddRef. The returned reference must not outlive self, and
only #[implement]-generated objects may recognize this IID.
Sourcefn is_object<T>(&self) -> bool
fn is_object<T>(&self) -> bool
Returns true if the given COM interface refers to an implementation of T.
Returns false if the object is not a Rust object, not T, or contains non-static
lifetimes.
Sourcefn cast_object_ref<T>(&self) -> Result<&<T as ComObjectInner>::Outer, Error>
fn cast_object_ref<T>(&self) -> Result<&<T as ComObjectInner>::Outer, Error>
Returns a borrowed reference to the generated outer Rust implementation.
Returns Err(E_NOINTERFACE) if the object is not a Rust object, not T, or contains
non-static lifetimes.
The returned value is borrowed; use Interface::cast_object for an owned (counted)
reference.
Sourcefn cast_object<T>(&self) -> Result<ComObject<T>, Error>
fn cast_object<T>(&self) -> Result<ComObject<T>, Error>
Returns an owned reference to the generated outer Rust implementation.
Returns Err(E_NOINTERFACE) if the object is not a Rust object, not T, or contains
non-static lifetimes.
The returned value is an owned (counted) reference: this function calls AddRef. Use
Interface::cast_object_ref to avoid AddRef / Release overhead if you do not need
ownership.
Sourcefn downgrade(&self) -> Result<Weak<Self>, Error>
fn downgrade(&self) -> Result<Weak<Self>, Error>
Attempts to create a Weak reference to this object.
Sourceunsafe fn query(&self, iid: *const GUID, interface: *mut *mut c_void) -> HRESULT
unsafe fn query(&self, iid: *const GUID, interface: *mut *mut c_void) -> HRESULT
Calls QueryInterface.
§Safety
interface must be a non-null, valid pointer for writing an interface pointer.
Sourcefn to_ref(&self) -> InterfaceRef<'_, Self>
fn to_ref(&self) -> InterfaceRef<'_, Self>
Borrows this interface without changing its reference count.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".