Struct intercom::ComBoxData
source · [−]#[repr(C)]pub struct ComBoxData<T: ComClass> { /* private fields */ }
Expand description
Type factory for the concrete COM coclass types.
Includes the virtual tables required for COM method invocations, reference
count required for IUnknown
implementation and the custom value struct
required for any user defined interfaces.
While this struct is available for manual handling of raw COM interface pointers, it’s worth realizing that it’s use is inherently unsafe. Most of the methods implemented for the type come with conditions that Rust isn’t able to enforce.
The methods that handle RawComPtr
types must only be invoked with correct
pointer values. There’s no type checking for the pointers and the ComBoxData
will make serious assumptions on the pointers passed in.
Furthermore the new_ptr
constructor and the IUnknown
methods add_ref
and release
must be used correctly together. Failure to do so will result
either in memory leaks or access to dangling pointers.
Implementations
sourceimpl<T: ComClass> ComBoxData<T>
impl<T: ComClass> ComBoxData<T>
sourcepub fn new(value: T) -> *mut ComBoxData<T>
pub fn new(value: T) -> *mut ComBoxData<T>
Creates a new ComBoxData and returns a pointer to it.
The box is initialized with a reference count of zero. In most cases the ComBoxData creation is followed by query_interface, which increments the ref_count.
The value should be cleaned by calling ‘release’.
sourcepub unsafe fn query_interface(
this: &Self,
riid: REFIID,
out: *mut RawComPtr
) -> HRESULT
pub unsafe fn query_interface(
this: &Self,
riid: REFIID,
out: *mut RawComPtr
) -> HRESULT
Acquires a specific interface pointer.
Increments the reference count to include the reference through the returned interface pointer.
The acquired interface must be released explicitly when not needed anymore.
Safety
The out
pointer must be valid for writing the interface pointer to.
sourcepub unsafe fn add_ref(this: &Self) -> u32
pub unsafe fn add_ref(this: &Self) -> u32
Increments the reference count.
Returns the reference count after the increment.
Safety
The method isn’t technically unsafe in regard to Rust unsafety, but it’s marked as unsafe to discourage it’s use due to high risks of memory leaks.
sourcepub fn get_ref_count(&self) -> u32
pub fn get_ref_count(&self) -> u32
Gets the reference count of the object.
sourcepub unsafe fn release(this: *mut Self) -> u32
pub unsafe fn release(this: *mut Self) -> u32
Decrements the reference count. Destroys the object if the count reaches zero.
Returns the reference count after the release.
Safety
The pointer must be valid and not previously released. After the call completes, the struct may have been deallocated and the pointer should be considered dangling.
sourcepub unsafe fn from_ptr<'a>(ptr: RawComPtr) -> &'a mut ComBoxData<T>
pub unsafe fn from_ptr<'a>(ptr: RawComPtr) -> &'a mut ComBoxData<T>
Converts a RawComPtr to a ComBoxData reference.
Safety
The method is unsafe in two different ways:
-
There is no way for the method to ensure the RawComPtr points to a valid ComBoxData
instance. It’s the caller’s responsibility to ensure the method is not called with invalid pointers. -
As the pointers have no lifetime tied to them, the borrow checker is unable to enforce the lifetime of the ComBoxData reference. If the ComBoxData is free’d by calling release on the pointer, the ComBoxData reference will still reference the old, now free’d value. The caller must ensure that the returned reference won’t be used in case the ComBoxData is released.
sourcepub fn vtable(ct: &ComBox<T>) -> &T::VTableList
pub fn vtable(ct: &ComBox<T>) -> &T::VTableList
Returns a reference to the virtual table on the ComBoxData.
sourcepub unsafe fn of(value: &T) -> &ComBoxData<T>
pub unsafe fn of(value: &T) -> &ComBoxData<T>
Gets the ComBoxData holding the value.
Safety
This is unsafe for two reasons:
-
There is no way for the method to check that the value is actually contained in a
ComBoxData
. It is up to the caller to ensure this method is only called with values that exist within aComBoxData
. -
The method returns a mutable reference to the ComBoxData containing the value. As demonstrated by the parameter type, the caller already has a mutable reference to the value itself. As a result the caller will end up with two different mutable references to the value - the direct one given as a parameter and an indirect one available through the return value. The caller should not attempt to access the value data through the returned
ComBoxData
reference.
sourcepub unsafe fn of_mut(value: &mut T) -> &mut ComBoxData<T>
pub unsafe fn of_mut(value: &mut T) -> &mut ComBoxData<T>
Gets the ComBoxData holding the value.
Safety
This is unsafe for two reasons:
-
There is no way for the method to check that the value is actually contained in a
ComBoxData
. It is up to the caller to ensure this method is only called with values that exist within aComBoxData
. -
The method returns a mutable reference to the ComBoxData containing the value. As demonstrated by the parameter type, the caller already has a mutable reference to the value itself. As a result the caller will end up with two different mutable references to the value - the direct one given as a parameter and an indirect one available through the return value. The caller should not attempt to access the value data through the returned
ComBoxData
reference.
sourcepub unsafe fn null_vtable() -> &'static T::VTableList
pub unsafe fn null_vtable() -> &'static T::VTableList
Returns a reference to a null-ComBoxData vtable pointer list.
Safety
The reference itself is invalid and must not be dereferenced.
The reference may be used to further get references to the various
VTableList fields to resolve offset values between the various VTable
pointers and the actual ComBoxData
containing these pointers.
Trait Implementations
sourceimpl<T: ComClass> AsMut<ComBoxData<T>> for ComBox<T>
impl<T: ComClass> AsMut<ComBoxData<T>> for ComBox<T>
sourcefn as_mut(&mut self) -> &mut ComBoxData<T>
fn as_mut(&mut self) -> &mut ComBoxData<T>
Converts this type into a mutable reference of the (usually inferred) input type.
sourceimpl<T: ComClass> AsRef<ComBoxData<T>> for ComBox<T>
impl<T: ComClass> AsRef<ComBoxData<T>> for ComBox<T>
sourcefn as_ref(&self) -> &ComBoxData<T>
fn as_ref(&self) -> &ComBoxData<T>
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl<T> Deref for ComBoxData<T> where
T: ComClass,
impl<T> Deref for ComBoxData<T> where
T: ComClass,
Auto Trait Implementations
impl<T> RefUnwindSafe for ComBoxData<T> where
T: RefUnwindSafe,
<T as ComClass>::VTableList: RefUnwindSafe,
impl<T> Send for ComBoxData<T> where
T: Send,
<T as ComClass>::VTableList: Send,
impl<T> Sync for ComBoxData<T> where
T: Sync,
<T as ComClass>::VTableList: Sync,
impl<T> Unpin for ComBoxData<T> where
T: Unpin,
<T as ComClass>::VTableList: Unpin,
impl<T> UnwindSafe for ComBoxData<T> where
T: UnwindSafe,
<T as ComClass>::VTableList: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ExternDefault for T
impl<T> ExternDefault for T
sourceunsafe fn extern_default() -> T
unsafe fn extern_default() -> T
Safety Read more