From 33b066f92678f3fbcf9b1b7bd57e61297a65689e Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Fri, 24 May 2024 14:47:19 -0700 Subject: [PATCH] update docs --- crates/libs/core/src/com_object.rs | 10 ++++------ crates/libs/core/src/interface.rs | 16 ++++++++-------- crates/tests/implement_core/src/com_object.rs | 3 +++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/libs/core/src/com_object.rs b/crates/libs/core/src/com_object.rs index fb133786641..ede313071e7 100644 --- a/crates/libs/core/src/com_object.rs +++ b/crates/libs/core/src/com_object.rs @@ -206,20 +206,18 @@ impl ComObject { /// 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(self, interface: IR) -> crate::Result + pub fn cast_from(interface: &I) -> crate::Result where - IR: AsRef, I: Interface, T::Outer: Any + 'static + IUnknownImpl, { - let interface_ref: &I = interface.as_ref(); - interface_ref.cast_object() + interface.cast_object() } } diff --git a/crates/libs/core/src/interface.rs b/crates/libs/core/src/interface.rs index 174fa94d028..93708fe9e31 100644 --- a/crates/libs/core/src/interface.rs +++ b/crates/libs/core/src/interface.rs @@ -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 /// @@ -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(&self) -> bool where @@ -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`]. @@ -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 diff --git a/crates/tests/implement_core/src/com_object.rs b/crates/tests/implement_core/src/com_object.rs index 598a8199a1d..de37c49bf99 100644 --- a/crates/tests/implement_core/src/com_object.rs +++ b/crates/tests/implement_core/src/com_object.rs @@ -371,6 +371,9 @@ fn dynamic_cast() { let dyn_app_owned: ComObject = unknown.cast_object().unwrap(); assert_eq!(dyn_app_owned.signature, APP_SIGNATURE); + + let dyn_app_owned_2: ComObject = 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.