Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlie Davis committed May 24, 2024
1 parent b87a217 commit 33b066f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
10 changes: 4 additions & 6 deletions crates/libs/core/src/com_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,18 @@ impl<T: ComObjectInner> ComObject<T> {
/// returned `&dyn Any` refers to the _outer_ implementation object that was generated by
/// `#[implement]`, i.e. the `MyApp_Impl` type, not the inner `MyApp` type.
///
/// If the given object is not a Rust object, or is a Rust object but not `T`, then this
/// function will return `Err(E_NOINTERFACE)`.
/// If the given object is not a Rust object, or is a Rust object but not `T`, or is a Rust
/// object that contains non-static lifetimes, then this function will return `Err(E_NOINTERFACE)`.
///
/// The returned value is an owned (counted) reference; this function calls `AddRef` on the
/// underlying COM object. If you do not need an owned reference, then you can use the
/// [`Interface::cast_object_ref`] method instead, and avoid the cost of `AddRef` / `Release`.
pub fn cast_from<IR, I>(self, interface: IR) -> crate::Result<Self>
pub fn cast_from<I>(interface: &I) -> crate::Result<Self>
where
IR: AsRef<I>,
I: Interface,
T::Outer: Any + 'static + IUnknownImpl<Impl = T>,
{
let interface_ref: &I = interface.as_ref();
interface_ref.cast_object()
interface.cast_object()
}
}

Expand Down
16 changes: 8 additions & 8 deletions crates/libs/core/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub unsafe trait Interface: Sized + Clone {
/// returned `&dyn Any` refers to the _outer_ implementation object that was generated by
/// `#[implement]`, i.e. the `MyApp_Impl` type, not the inner `MyApp` type.
///
/// If the given object is not a Rust object, or is a Rust object but not `T`, then this
/// function will return `Err(E_NOINTERFACE)`.
/// If the given object is not a Rust object, or is a Rust object but not `T`, or is a Rust
/// object that contains non-static lifetimes, then this function will return `Err(E_NOINTERFACE)`.
///
/// # Safety
///
Expand Down Expand Up @@ -162,8 +162,8 @@ pub unsafe trait Interface: Sized + Clone {
/// `T` must be a type that has been annotated with `#[implement]`; this is checked at
/// compile-time by the generic constraints of this method.
///
/// If the given object is not a Rust object, or is a Rust object but not `T`, then this
/// function will return `false`.
/// If the given object is not a Rust object, or is a Rust object but not `T`, or is a Rust
/// object that contains non-static lifetimes, then this function will return `false`.
#[inline(always)]
fn is_object<T>(&self) -> bool
where
Expand All @@ -185,8 +185,8 @@ pub unsafe trait Interface: Sized + Clone {
/// returned `&dyn Any` refers to the _outer_ implementation object that was generated by
/// `#[implement]`, i.e. the `MyApp_Impl` type, not the inner `MyApp` type.
///
/// If the given object is not a Rust object, or is a Rust object but not `T`, then this
/// function will return `Err(E_NOINTERFACE)`.
/// If the given object is not a Rust object, or is a Rust object but not `T`, or is a Rust
/// object that contains non-static lifetimes, then this function will return `Err(E_NOINTERFACE)`.
///
/// The returned value is borrowed. If you need an owned (counted) reference, then use
/// [`Interface::cast_object`].
Expand All @@ -212,8 +212,8 @@ pub unsafe trait Interface: Sized + Clone {
/// returned `&dyn Any` refers to the _outer_ implementation object that was generated by
/// `#[implement]`, i.e. the `MyApp_Impl` type, not the inner `MyApp` type.
///
/// If the given object is not a Rust object, or is a Rust object but not `T`, then this
/// function will return `Err(E_NOINTERFACE)`.
/// If the given object is not a Rust object, or is a Rust object but not `T`, or is a Rust
/// object that contains non-static lifetimes, then this function will return `Err(E_NOINTERFACE)`.
///
/// The returned value is an owned (counted) reference; this function calls `AddRef` on the
/// underlying COM object. If you do not need an owned reference, then you can use the
Expand Down
3 changes: 3 additions & 0 deletions crates/tests/implement_core/src/com_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ fn dynamic_cast() {

let dyn_app_owned: ComObject<MyApp> = unknown.cast_object().unwrap();
assert_eq!(dyn_app_owned.signature, APP_SIGNATURE);

let dyn_app_owned_2: ComObject<MyApp> = ComObject::cast_from(&unknown).unwrap();
assert_eq!(dyn_app_owned_2.signature, APP_SIGNATURE);
}

// This tests that we can place a type that is not Send in a ComObject.
Expand Down

0 comments on commit 33b066f

Please sign in to comment.