pub struct ComRef<'a, I>where
I: Interface,{ /* private fields */ }
Expand description
A non-owning smart pointer to a COM object.
A ComRef<'a, I>
represents a borrowed reference to a COM object implementing interface I
.
Like ComPtr
, ComRef
can be used to call interface methods on the referenced object.
Unlike ComPtr
, ComRef
does not manage the object’s reference count, i.e. it will not
call the release method of the object it points to when going out of scope. See the
crate-level documentation for more information.
A ComRef
can be created safely from a ComPtr
via ComPtr::as_com_ref
, or from a
ComWrapper
via ComWrapper::as_com_ref
.
It can also be created unsafely via ComRef::from_raw
.
Implementations§
source§impl<'a, I> ComRef<'a, I>where
I: Interface,
impl<'a, I> ComRef<'a, I>where
I: Interface,
sourcepub fn as_ptr(&self) -> *mut I
pub fn as_ptr(&self) -> *mut I
Gets the wrapped interface pointer.
Does not perform any reference counting operations.
sourcepub unsafe fn from_raw(ptr: *mut I) -> Option<ComRef<'a, I>>
pub unsafe fn from_raw(ptr: *mut I) -> Option<ComRef<'a, I>>
Creates a ComRef
from a raw interface pointer if the pointer is non-null.
Does not perform any reference counting operations.
from_raw
will check if ptr
is null (and return None
if so), but this method is still
unsafe, as the caller must still ensure that ptr
is a valid interface pointer (see below)
if it is non-null.
§Safety
If ptr
is non-null, it must be a valid pointer to a value of type I
, and if *ptr
is
reinterpreted as *const I::Vtbl
(see the safety documentation for
Interface
), it must in turn be a valid pointer to I::Vtbl
.
sourcepub unsafe fn from_raw_unchecked(ptr: *mut I) -> ComRef<'a, I>
pub unsafe fn from_raw_unchecked(ptr: *mut I) -> ComRef<'a, I>
Creates a ComRef
from a raw interface pointer.
Does not perform any reference counting operations.
§Safety
ptr
must be a valid pointer to a value of type I
, and if *ptr
is reinterpreted as
*const I::Vtbl
(see the safety documentation for Interface
), it
must in turn be a valid pointer to I::Vtbl
.
sourcepub fn to_com_ptr(&self) -> ComPtr<I>
pub fn to_com_ptr(&self) -> ComPtr<I>
Upgrades the ComRef
to a ComPtr
.
Increments the reference count of the object that the ComRef
points to.