Trait windows_core::Interface

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: Interface>(&self) -> Result<T> { ... }
    fn downgrade(&self) -> Result<Weak<Self>> { ... }
    unsafe fn query(
        &self,
        iid: *const GUID,
        interface: *mut *mut c_void
    ) -> HRESULT { ... }
}
Expand description

Provides low-level access to an interface vtable.

This trait is automatically implemented by the generated bindings and should not be implemented manually.

§Safety

Required Associated Constants§

const IID: GUID

The GUID associated with the interface.

Provided Methods§

fn as_raw(&self) -> *mut c_void

Returns the raw COM interface pointer. The resulting pointer continues to be owned by the Interface implementation.

fn into_raw(self) -> *mut c_void

Returns the raw COM interface pointer and releases ownership. It the caller’s responsibility to release the COM interface pointer.

unsafe fn from_raw(raw: *mut c_void) -> Self

Creates an Interface by taking ownership of the raw COM interface pointer.

§Safety

The raw pointer must be owned by the caller and represent a valid COM interface pointer. In other words, it must point to a vtable beginning with the IUnknown function pointers and match the vtable of Interface.

unsafe fn from_raw_borrowed(raw: &*mut c_void) -> Option<&Self>

Creates an Interface that is valid so long as the raw COM interface pointer is valid.

§Safety

The raw pointer must be a valid COM interface pointer. In other words, it must point to a vtable beginning with the IUnknown function pointers and match the vtable of Interface.

fn cast<T: Interface>(&self) -> Result<T>

Attempts to cast the current interface to another interface using QueryInterface.

The name cast is preferred to query because there is a WinRT method named query but not one named cast.

fn downgrade(&self) -> Result<Weak<Self>>

Attempts to create a Weak reference to this object.

unsafe fn query(&self, iid: *const GUID, interface: *mut *mut c_void) -> HRESULT

Call QueryInterface on this interface

§Safety

interface must be a non-null, valid pointer for writing an interface pointer.

Object Safety§

This trait is not object safe.

Implementors§

§

impl Interface for IInspectable

§

const IID: GUID = _

§

impl Interface for IUnknown

§

const IID: GUID = _