pub struct ComRef<'a, 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: Interface> ComRef<'a, I>

source

pub fn as_ptr(&self) -> *mut I

Gets the wrapped interface pointer.

Does not perform any reference counting operations.

source

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.

source

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.

source

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.

source

pub fn upcast<J: Interface>(self) -> ComRef<'a, J>
where I: Inherits<J>,

Casts the ComRef from a derived interface to a base interface.

Does not perform any reference counting operations.

source

pub fn cast<J: Interface>(&self) -> Option<ComPtr<J>>

Attempts to cast from one interface to another, returning a ComPtr if successful.

If the cast is successful, increments the reference count of the object that the ComRef points to.

Trait Implementations§

source§

impl<'a, I: Interface> Clone for ComRef<'a, I>

source§

fn clone(&self) -> ComRef<'a, I>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, I: Interface> SmartPtr for ComRef<'a, I>

§

type Target = I

The interface type pointed to by this smart pointer.
source§

fn ptr(&self) -> *mut I

Gets the raw pointer held by this smart pointer.
source§

impl<'a, I: Interface> Copy for ComRef<'a, I>

source§

impl<'a, I> Send for ComRef<'a, I>
where I: Sync + Send + Interface,

source§

impl<'a, I> Sync for ComRef<'a, I>
where I: Sync + Send + Interface,

Auto Trait Implementations§

§

impl<'a, I> RefUnwindSafe for ComRef<'a, I>
where I: RefUnwindSafe,

§

impl<'a, I> Unpin for ComRef<'a, I>

§

impl<'a, I> UnwindSafe for ComRef<'a, I>
where I: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.