Trait Interface
pub unsafe trait Interface: Sized + Clone {
const IID: GUID;
Show 13 methods
// 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 as_interface<T: Interface>(&self) -> &T { ... }
fn cast<T: Interface>(&self) -> Result<T> { ... }
fn cast_to_any<T>(&self) -> Result<&dyn Any>
where T: ComObjectInner,
T::Outer: Any + 'static + IUnknownImpl<Impl = T> { ... }
fn is_object<T>(&self) -> bool
where T: ComObjectInner,
T::Outer: Any + 'static + IUnknownImpl<Impl = T> { ... }
fn cast_object_ref<T>(&self) -> Result<&T::Outer>
where T: ComObjectInner,
T::Outer: Any + 'static + IUnknownImpl<Impl = T> { ... }
fn cast_object<T>(&self) -> Result<ComObject<T>>
where T: ComObjectInner,
T::Outer: Any + 'static + IUnknownImpl<Impl = T> { ... }
fn downgrade(&self) -> Result<Weak<Self>> { ... }
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§
unsafe 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.
unsafe 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.
fn as_interface<T: Interface>(&self) -> &T
fn as_interface<T: Interface>(&self) -> &T
Borrows this interface as T without calling QueryInterface or AddRef.
T is the same COM interface from other bindings, such as a crate’s private bindings and
the windows crate. A T with a different IID fails to build; use cast
to query for another interface.
fn cast_to_any<T>(&self) -> Result<&dyn Any>
fn cast_to_any<T>(&self) -> Result<&dyn Any>
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 the COM error if the private Rust interface cannot be queried.
§Safety
This queries a private COM interface identified by DYNAMIC_CAST_IID, then borrows the
Rust implementation through that interface. It has no proxy/stub support, so a COM proxy
cannot provide access to the Rust implementation.
The returned reference must not outlive self. Only generated Rust objects may recognize
this IID.
fn 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.
fn cast_object_ref<T>(&self) -> Result<&T::Outer>
fn cast_object_ref<T>(&self) -> Result<&T::Outer>
Returns a borrowed reference to the generated outer Rust implementation.
Returns Err(E_NOINTERFACE) for a type mismatch. Errors querying the private Rust
interface, including through COM proxies, are propagated.
The returned value is borrowed; use Interface::cast_object for an owned (counted)
reference.
fn cast_object<T>(&self) -> Result<ComObject<T>>
fn cast_object<T>(&self) -> Result<ComObject<T>>
Returns an owned reference to the generated outer Rust implementation.
Fails under the same conditions as Interface::cast_object_ref.
The returned value is an owned (counted) reference: this function calls AddRef. Use
Interface::cast_object_ref if you do not need to retain an additional reference.
unsafe 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.
fn 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".