diff --git a/crates/libs/bindgen/src/types/method.rs b/crates/libs/bindgen/src/types/method.rs index 0924014bf6a..75b65825e23 100644 --- a/crates/libs/bindgen/src/types/method.rs +++ b/crates/libs/bindgen/src/types/method.rs @@ -150,9 +150,12 @@ impl Method { quote! { &[#default_type] } } else if p.is_primitive(config.reader) { quote! { #default_type } - } else if p.is_interface() || matches!(&p.ty, Type::Generic(_)) { + } else if p.is_interface() { let type_name = p.write_name(config); quote! { windows_core::Ref<#type_name> } + } else if matches!(&p.ty, Type::Generic(_)) { + let type_name = p.write_name(config); + quote! { windows_core::Generic<#type_name> } } else { quote! { &#default_type } } diff --git a/crates/libs/collections/src/bindings.rs b/crates/libs/collections/src/bindings.rs index e987a6f2adc..ca495fc8e7d 100644 --- a/crates/libs/collections/src/bindings.rs +++ b/crates/libs/collections/src/bindings.rs @@ -679,16 +679,16 @@ where K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'static, { - fn Lookup(&self, key: windows_core::Ref) -> windows_core::Result; + fn Lookup(&self, key: windows_core::Generic) -> windows_core::Result; fn Size(&self) -> windows_core::Result; - fn HasKey(&self, key: windows_core::Ref) -> windows_core::Result; + fn HasKey(&self, key: windows_core::Generic) -> windows_core::Result; fn GetView(&self) -> windows_core::Result>; fn Insert( &self, - key: windows_core::Ref, - value: windows_core::Ref, + key: windows_core::Generic, + value: windows_core::Generic, ) -> windows_core::Result; - fn Remove(&self, key: windows_core::Ref) -> windows_core::Result<()>; + fn Remove(&self, key: windows_core::Generic) -> windows_core::Result<()>; fn Clear(&self) -> windows_core::Result<()>; } impl @@ -1166,9 +1166,9 @@ where K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'static, { - fn Lookup(&self, key: windows_core::Ref) -> windows_core::Result; + fn Lookup(&self, key: windows_core::Generic) -> windows_core::Result; fn Size(&self) -> windows_core::Result; - fn HasKey(&self, key: windows_core::Ref) -> windows_core::Result; + fn HasKey(&self, key: windows_core::Generic) -> windows_core::Result; fn Split( &self, first: windows_core::OutRef>, @@ -2121,11 +2121,15 @@ where fn GetAt(&self, index: u32) -> windows_core::Result; fn Size(&self) -> windows_core::Result; fn GetView(&self) -> windows_core::Result>; - fn IndexOf(&self, value: windows_core::Ref, index: &mut u32) -> windows_core::Result; - fn SetAt(&self, index: u32, value: windows_core::Ref) -> windows_core::Result<()>; - fn InsertAt(&self, index: u32, value: windows_core::Ref) -> windows_core::Result<()>; + fn IndexOf( + &self, + value: windows_core::Generic, + index: &mut u32, + ) -> windows_core::Result; + fn SetAt(&self, index: u32, value: windows_core::Generic) -> windows_core::Result<()>; + fn InsertAt(&self, index: u32, value: windows_core::Generic) -> windows_core::Result<()>; fn RemoveAt(&self, index: u32) -> windows_core::Result<()>; - fn Append(&self, value: windows_core::Ref) -> windows_core::Result<()>; + fn Append(&self, value: windows_core::Generic) -> windows_core::Result<()>; fn RemoveAtEnd(&self) -> windows_core::Result<()>; fn Clear(&self) -> windows_core::Result<()>; fn GetMany( @@ -2666,7 +2670,11 @@ where { fn GetAt(&self, index: u32) -> windows_core::Result; fn Size(&self) -> windows_core::Result; - fn IndexOf(&self, value: windows_core::Ref, index: &mut u32) -> windows_core::Result; + fn IndexOf( + &self, + value: windows_core::Generic, + index: &mut u32, + ) -> windows_core::Result; fn GetMany( &self, startIndex: u32, diff --git a/crates/libs/collections/src/map.rs b/crates/libs/collections/src/map.rs index 80434ec0036..fd2c23cc038 100644 --- a/crates/libs/collections/src/map.rs +++ b/crates/libs/collections/src/map.rs @@ -35,9 +35,11 @@ where K::Default: Clone + Ord, V::Default: Clone, { - fn Lookup(&self, key: Ref) -> Result { + fn Lookup(&self, key: Generic) -> Result { let map = self.map.read().unwrap(); - let value = map.get(&*key).ok_or_else(|| Error::from(E_BOUNDS))?; + let value = map + .get(generic_as_default::(&key)) + .ok_or_else(|| Error::from(E_BOUNDS))?; V::from_default(value) } @@ -45,8 +47,12 @@ where Ok(self.map.read().unwrap().len().try_into()?) } - fn HasKey(&self, key: Ref) -> Result { - Ok(self.map.read().unwrap().contains_key(&*key)) + fn HasKey(&self, key: Generic) -> Result { + Ok(self + .map + .read() + .unwrap() + .contains_key(generic_as_default::(&key))) } fn GetView(&self) -> Result> { @@ -54,16 +60,19 @@ where Ok(IMapView::::from(snapshot)) } - fn Insert(&self, key: Ref, value: Ref) -> Result { + fn Insert(&self, key: Generic, value: Generic) -> Result { let mut map = self.map.write().unwrap(); - let replaced = map.contains_key(&*key); - map.insert((*key).clone(), (*value).clone()); + let replaced = map.contains_key(generic_as_default::(&key)); + map.insert( + generic_as_default::(&key).clone(), + generic_as_default::(&value).clone(), + ); Ok(replaced) } - fn Remove(&self, key: Ref) -> Result<()> { + fn Remove(&self, key: Generic) -> Result<()> { let mut map = self.map.write().unwrap(); - if map.remove(&*key).is_none() { + if map.remove(generic_as_default::(&key)).is_none() { return Err(Error::from(E_BOUNDS)); } Ok(()) diff --git a/crates/libs/collections/src/map_view.rs b/crates/libs/collections/src/map_view.rs index 50c03936a88..5859b77a220 100644 --- a/crates/libs/collections/src/map_view.rs +++ b/crates/libs/collections/src/map_view.rs @@ -35,8 +35,11 @@ where K::Default: Clone + Ord, V::Default: Clone, { - fn Lookup(&self, key: Ref) -> Result { - let value = self.map.get(&*key).ok_or_else(|| Error::from(E_BOUNDS))?; + fn Lookup(&self, key: Generic) -> Result { + let value = self + .map + .get(generic_as_default::(&key)) + .ok_or_else(|| Error::from(E_BOUNDS))?; V::from_default(value) } @@ -45,8 +48,8 @@ where Ok(self.map.len().try_into()?) } - fn HasKey(&self, key: Ref) -> Result { - Ok(self.map.contains_key(&*key)) + fn HasKey(&self, key: Generic) -> Result { + Ok(self.map.contains_key(generic_as_default::(&key))) } fn Split(&self, first: OutRef>, second: OutRef>) -> Result<()> { diff --git a/crates/libs/collections/src/observable_map.rs b/crates/libs/collections/src/observable_map.rs index 1d42f2cc045..02a52001efb 100644 --- a/crates/libs/collections/src/observable_map.rs +++ b/crates/libs/collections/src/observable_map.rs @@ -53,9 +53,11 @@ where K::Default: Clone + Ord, V::Default: Clone, { - fn Lookup(&self, key: Ref) -> Result { + fn Lookup(&self, key: Generic) -> Result { let map = self.map.read().unwrap(); - let value = map.get(&*key).ok_or_else(|| Error::from(E_BOUNDS))?; + let value = map + .get(generic_as_default::(&key)) + .ok_or_else(|| Error::from(E_BOUNDS))?; V::from_default(value) } @@ -63,8 +65,12 @@ where Ok(self.map.read().unwrap().len().try_into()?) } - fn HasKey(&self, key: Ref) -> Result { - Ok(self.map.read().unwrap().contains_key(&*key)) + fn HasKey(&self, key: Generic) -> Result { + Ok(self + .map + .read() + .unwrap() + .contains_key(generic_as_default::(&key))) } fn GetView(&self) -> Result> { @@ -72,11 +78,14 @@ where Ok(IMapView::::from(snapshot)) } - fn Insert(&self, key: Ref, value: Ref) -> Result { + fn Insert(&self, key: Generic, value: Generic) -> Result { let replaced = { let mut map = self.map.write().unwrap(); - let replaced = map.contains_key(&*key); - map.insert((*key).clone(), (*value).clone()); + let replaced = map.contains_key(generic_as_default::(&key)); + map.insert( + generic_as_default::(&key).clone(), + generic_as_default::(&value).clone(), + ); replaced }; let change = if replaced { @@ -84,15 +93,15 @@ where } else { CollectionChange::ItemInserted }; - self.fire_changed(change, Some((*key).clone())); + self.fire_changed(change, Some(generic_as_default::(&key).clone())); Ok(replaced) } - fn Remove(&self, key: Ref) -> Result<()> { - let key_clone = (*key).clone(); + fn Remove(&self, key: Generic) -> Result<()> { + let key_clone = generic_as_default::(&key).clone(); { let mut map = self.map.write().unwrap(); - if map.remove(&*key).is_none() { + if map.remove(generic_as_default::(&key)).is_none() { return Err(Error::from(E_BOUNDS)); } } diff --git a/crates/libs/collections/src/observable_vector.rs b/crates/libs/collections/src/observable_vector.rs index 7d25191c0bc..91e8cf538ee 100644 --- a/crates/libs/collections/src/observable_vector.rs +++ b/crates/libs/collections/src/observable_vector.rs @@ -62,9 +62,12 @@ where Ok(IVectorView::::from(snapshot)) } - fn IndexOf(&self, value: Ref, result: &mut u32) -> Result { + fn IndexOf(&self, value: Generic, result: &mut u32) -> Result { let values = self.values.read().unwrap(); - match values.iter().position(|element| element == &*value) { + match values + .iter() + .position(|element| element == generic_as_default::(&value)) + { Some(index) => { *result = index as u32; Ok(true) @@ -76,26 +79,26 @@ where } } - fn SetAt(&self, index: u32, value: Ref) -> Result<()> { + fn SetAt(&self, index: u32, value: Generic) -> Result<()> { { let mut values = self.values.write().unwrap(); let item = values .get_mut(index as usize) .ok_or_else(|| Error::from(E_BOUNDS))?; - *item = (*value).clone(); + *item = generic_as_default::(&value).clone(); } self.fire_changed(CollectionChange::ItemChanged, index); Ok(()) } - fn InsertAt(&self, index: u32, value: Ref) -> Result<()> { + fn InsertAt(&self, index: u32, value: Generic) -> Result<()> { { let mut values = self.values.write().unwrap(); let index = index as usize; if index > values.len() { return Err(Error::from(E_BOUNDS)); } - values.insert(index, (*value).clone()); + values.insert(index, generic_as_default::(&value).clone()); } self.fire_changed(CollectionChange::ItemInserted, index); Ok(()) @@ -113,10 +116,10 @@ where Ok(()) } - fn Append(&self, value: Ref) -> Result<()> { + fn Append(&self, value: Generic) -> Result<()> { let index = { let mut values = self.values.write().unwrap(); - values.push((*value).clone()); + values.push(generic_as_default::(&value).clone()); (values.len() - 1) as u32 }; self.fire_changed(CollectionChange::ItemInserted, index); diff --git a/crates/libs/collections/src/vector.rs b/crates/libs/collections/src/vector.rs index a45e253ae7b..842891e50d5 100644 --- a/crates/libs/collections/src/vector.rs +++ b/crates/libs/collections/src/vector.rs @@ -46,9 +46,12 @@ where Ok(IVectorView::::from(snapshot)) } - fn IndexOf(&self, value: Ref, result: &mut u32) -> Result { + fn IndexOf(&self, value: Generic, result: &mut u32) -> Result { let values = self.values.read().unwrap(); - match values.iter().position(|element| element == &*value) { + match values + .iter() + .position(|element| element == generic_as_default::(&value)) + { Some(index) => { *result = index as u32; Ok(true) @@ -60,22 +63,22 @@ where } } - fn SetAt(&self, index: u32, value: Ref) -> Result<()> { + fn SetAt(&self, index: u32, value: Generic) -> Result<()> { let mut values = self.values.write().unwrap(); let item = values .get_mut(index as usize) .ok_or_else(|| Error::from(E_BOUNDS))?; - *item = (*value).clone(); + *item = generic_as_default::(&value).clone(); Ok(()) } - fn InsertAt(&self, index: u32, value: Ref) -> Result<()> { + fn InsertAt(&self, index: u32, value: Generic) -> Result<()> { let mut values = self.values.write().unwrap(); let index = index as usize; if index > values.len() { return Err(Error::from(E_BOUNDS)); } - values.insert(index, (*value).clone()); + values.insert(index, generic_as_default::(&value).clone()); Ok(()) } @@ -88,8 +91,11 @@ where Ok(()) } - fn Append(&self, value: Ref) -> Result<()> { - self.values.write().unwrap().push((*value).clone()); + fn Append(&self, value: Generic) -> Result<()> { + self.values + .write() + .unwrap() + .push(generic_as_default::(&value).clone()); Ok(()) } diff --git a/crates/libs/collections/src/vector_view.rs b/crates/libs/collections/src/vector_view.rs index 7978bf9dd58..e34d5d2bbcb 100644 --- a/crates/libs/collections/src/vector_view.rs +++ b/crates/libs/collections/src/vector_view.rs @@ -42,8 +42,12 @@ where Ok(self.values.len().try_into()?) } - fn IndexOf(&self, value: Ref, result: &mut u32) -> Result { - match self.values.iter().position(|element| element == &*value) { + fn IndexOf(&self, value: Generic, result: &mut u32) -> Result { + match self + .values + .iter() + .position(|element| element == generic_as_default::(&value)) + { Some(index) => { *result = index as u32; Ok(true) diff --git a/crates/libs/core/src/type.rs b/crates/libs/core/src/type.rs index a64f191d0a2..4ecf22d9070 100644 --- a/crates/libs/core/src/type.rs +++ b/crates/libs/core/src/type.rs @@ -19,6 +19,16 @@ pub trait Type::TypeKind>: TypeKind + Sized + C type Abi; type Default; + /// The parameter type used in `_Impl` trait method signatures. + /// + /// For `CopyType` (primitives, enums, GUID, etc.) this is `T` directly — the type itself, + /// since these are cheap to copy and `Ref` adds no value. For `CloneType` (HSTRING, etc.) + /// and `InterfaceType` (COM interfaces) this is `Ref<'a, T>` — a borrowed wrapper that + /// matches the ABI representation. + type Generic<'a>: 'a + where + Self: 'a; + fn is_null(abi: &Self::Abi) -> bool; unsafe fn assume_init_ref(abi: &Self::Abi) -> &Self; unsafe fn from_abi(abi: Self::Abi) -> Result; @@ -31,6 +41,10 @@ where { type Abi = *mut core::ffi::c_void; type Default = Option; + type Generic<'a> + = Ref<'a, Self> + where + Self: 'a; fn is_null(abi: &Self::Abi) -> bool { abi.is_null() @@ -61,6 +75,10 @@ where { type Abi = core::mem::MaybeUninit; type Default = Self; + type Generic<'a> + = Ref<'a, Self> + where + Self: 'a; fn is_null(_: &Self::Abi) -> bool { false @@ -85,6 +103,10 @@ where { type Abi = Self; type Default = Self; + type Generic<'a> + = Self + where + Self: 'a; fn is_null(_: &Self::Abi) -> bool { false @@ -125,3 +147,37 @@ primitives!(bool, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, usize, isize); #[doc(hidden)] pub type AbiType = >::Abi; + +/// The parameter type for a generic type `T` used in `_Impl` trait method signatures. +/// +/// For `CopyType` (primitives, enums, GUID, etc.) this resolves to `T` directly — the type +/// itself, since these are cheap to copy and no wrapper is needed. For all other types +/// (`CloneType` such as `HSTRING`, and `InterfaceType` such as COM interfaces) this resolves +/// to [`Ref<'a, T>`], a borrowed wrapper that matches the ABI layout. +/// +/// # Example +/// +/// ```rust,ignore +/// impl IMap_Impl for MyMap_Impl { +/// fn HasKey(&self, key: Generic) -> Result { +/// // key is just i32 — no Ref wrapper needed +/// Ok(self.map.contains_key(&key)) +/// } +/// } +/// ``` +pub type Generic<'a, T> = >::Generic<'a>; + +/// Converts a [`Generic`](Generic) reference into a reference to the corresponding +/// [`Default`](Type::Default) representation. +/// +/// `Generic` and `T::Default` always share the same memory layout, so this is a +/// zero-cost reinterpretation: +/// - For `CopyType` (primitives, GUID, enums): `Generic<'_> = T = Default`, no-op. +/// - For `CloneType` (HSTRING, etc.) and `InterfaceType` (COM interfaces): +/// `Generic<'_> = Ref<'_, T>`, which is `#[repr(transparent)]` over `T::Abi`, and +/// `T::Abi` has the same layout as `T::Default`. +pub fn generic_as_default<'a, 'b, T: Type>( + param: &'a >::Generic<'b>, +) -> &'a T::Default { + unsafe { &*(param as *const >::Generic<'b> as *const T::Default) } +} diff --git a/crates/libs/future/src/bindings.rs b/crates/libs/future/src/bindings.rs index a94f1f88d9b..e60d14ec706 100644 --- a/crates/libs/future/src/bindings.rs +++ b/crates/libs/future/src/bindings.rs @@ -160,7 +160,7 @@ impl AsyncActionProgressHandler< pub fn new< F: Fn( windows_core::Ref>, - windows_core::Ref, + windows_core::Generic, ) -> windows_core::Result<()> + Send + 'static, @@ -209,7 +209,7 @@ struct AsyncActionProgressHandlerBox< TProgress, F: Fn( windows_core::Ref>, - windows_core::Ref, + windows_core::Generic, ) -> windows_core::Result<()> + Send + 'static, @@ -224,7 +224,7 @@ impl< TProgress: windows_core::RuntimeType + 'static, F: Fn( windows_core::Ref>, - windows_core::Ref, + windows_core::Generic, ) -> windows_core::Result<()> + Send + 'static, @@ -665,7 +665,7 @@ impl< pub fn new< F: Fn( windows_core::Ref>, - windows_core::Ref, + windows_core::Generic, ) -> windows_core::Result<()> + Send + 'static, @@ -717,7 +717,7 @@ struct AsyncOperationProgressHandlerBox< TProgress, F: Fn( windows_core::Ref>, - windows_core::Ref, + windows_core::Generic, ) -> windows_core::Result<()> + Send + 'static, @@ -734,7 +734,7 @@ impl< TProgress: windows_core::RuntimeType + 'static, F: Fn( windows_core::Ref>, - windows_core::Ref, + windows_core::Generic, ) -> windows_core::Result<()> + Send + 'static, diff --git a/crates/libs/windows/src/Windows/Foundation/mod.rs b/crates/libs/windows/src/Windows/Foundation/mod.rs index 3aee5b30021..d7f299b372b 100644 --- a/crates/libs/windows/src/Windows/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/mod.rs @@ -145,7 +145,7 @@ impl windows_core::RuntimeType for Event const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::new().push_slice(b"pinterface({9de1c535-6ae1-11e0-84e1-18a905bcc53f}").push_slice(b";").push_other(T::SIGNATURE).push_slice(b")"); } impl EventHandler { - pub fn new, windows_core::Ref) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self { + pub fn new, windows_core::Generic) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self { let com = EventHandlerBox { vtable: &EventHandlerBox::::VTABLE, count: windows_core::imp::RefCount::new(1), invoke }; unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) } } @@ -169,7 +169,7 @@ where T: core::marker::PhantomData, } #[repr(C)] -struct EventHandlerBox, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> +struct EventHandlerBox, windows_core::Generic) -> windows_core::Result<()> + Send + 'static> where T: windows_core::RuntimeType + 'static, { @@ -177,7 +177,7 @@ where invoke: F, count: windows_core::imp::RefCount, } -impl, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> EventHandlerBox { +impl, windows_core::Generic) -> windows_core::Result<()> + Send + 'static> EventHandlerBox { const VTABLE: EventHandler_Vtbl = EventHandler_Vtbl:: { base__: windows_core::IUnknown_Vtbl { QueryInterface: Self::QueryInterface, AddRef: Self::AddRef, Release: Self::Release }, Invoke: Self::Invoke, @@ -2468,7 +2468,7 @@ impl TypedEventHandler { - pub fn new, windows_core::Ref) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self { + pub fn new, windows_core::Generic) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self { let com = TypedEventHandlerBox { vtable: &TypedEventHandlerBox::::VTABLE, count: windows_core::imp::RefCount::new(1), invoke }; unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) } } @@ -2494,7 +2494,7 @@ where TResult: core::marker::PhantomData, } #[repr(C)] -struct TypedEventHandlerBox, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> +struct TypedEventHandlerBox, windows_core::Generic) -> windows_core::Result<()> + Send + 'static> where TSender: windows_core::RuntimeType + 'static, TResult: windows_core::RuntimeType + 'static, @@ -2503,7 +2503,7 @@ where invoke: F, count: windows_core::imp::RefCount, } -impl, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> TypedEventHandlerBox { +impl, windows_core::Generic) -> windows_core::Result<()> + Send + 'static> TypedEventHandlerBox { const VTABLE: TypedEventHandler_Vtbl = TypedEventHandler_Vtbl:: { base__: windows_core::IUnknown_Vtbl { QueryInterface: Self::QueryInterface, AddRef: Self::AddRef, Release: Self::Release }, Invoke: Self::Invoke, diff --git a/crates/tests/libs/bindgen/src/class_dep.rs b/crates/tests/libs/bindgen/src/class_dep.rs index 35b661a5e96..91f2d58ffa0 100644 --- a/crates/tests/libs/bindgen/src/class_dep.rs +++ b/crates/tests/libs/bindgen/src/class_dep.rs @@ -468,7 +468,11 @@ where { fn GetAt(&self, index: u32) -> windows_core::Result; fn Size(&self) -> windows_core::Result; - fn IndexOf(&self, value: windows_core::Ref, index: &mut u32) -> windows_core::Result; + fn IndexOf( + &self, + value: windows_core::Generic, + index: &mut u32, + ) -> windows_core::Result; fn GetMany( &self, startIndex: u32, diff --git a/crates/tests/libs/bindgen/src/delegate_generic.rs b/crates/tests/libs/bindgen/src/delegate_generic.rs index a1a83814880..84b4485dd58 100644 --- a/crates/tests/libs/bindgen/src/delegate_generic.rs +++ b/crates/tests/libs/bindgen/src/delegate_generic.rs @@ -27,7 +27,7 @@ impl EventHandler { pub fn new< F: Fn( windows_core::Ref, - windows_core::Ref, + windows_core::Generic, ) -> windows_core::Result<()> + Send + 'static, @@ -76,7 +76,7 @@ struct EventHandlerBox< T, F: Fn( windows_core::Ref, - windows_core::Ref, + windows_core::Generic, ) -> windows_core::Result<()> + Send + 'static, @@ -91,7 +91,7 @@ impl< T: windows_core::RuntimeType + 'static, F: Fn( windows_core::Ref, - windows_core::Ref, + windows_core::Generic, ) -> windows_core::Result<()> + Send + 'static, diff --git a/crates/tests/libs/bindgen/src/interface_iterable.rs b/crates/tests/libs/bindgen/src/interface_iterable.rs index 2213067209c..f420fda072c 100644 --- a/crates/tests/libs/bindgen/src/interface_iterable.rs +++ b/crates/tests/libs/bindgen/src/interface_iterable.rs @@ -549,11 +549,15 @@ where { fn GetAt(&self, index: u32) -> windows_core::Result; fn Size(&self) -> windows_core::Result; - fn IndexOf(&self, value: windows_core::Ref, index: &mut u32) -> windows_core::Result; - fn SetAt(&self, index: u32, value: windows_core::Ref) -> windows_core::Result<()>; - fn InsertAt(&self, index: u32, value: windows_core::Ref) -> windows_core::Result<()>; + fn IndexOf( + &self, + value: windows_core::Generic, + index: &mut u32, + ) -> windows_core::Result; + fn SetAt(&self, index: u32, value: windows_core::Generic) -> windows_core::Result<()>; + fn InsertAt(&self, index: u32, value: windows_core::Generic) -> windows_core::Result<()>; fn RemoveAt(&self, index: u32) -> windows_core::Result<()>; - fn Append(&self, value: windows_core::Ref) -> windows_core::Result<()>; + fn Append(&self, value: windows_core::Generic) -> windows_core::Result<()>; fn RemoveAtEnd(&self) -> windows_core::Result<()>; fn Clear(&self) -> windows_core::Result<()>; fn GetMany( diff --git a/crates/tests/libs/collections/tests/stock_observable_map.rs b/crates/tests/libs/collections/tests/stock_observable_map.rs index 5a56697a58f..43fb17aba66 100644 --- a/crates/tests/libs/collections/tests/stock_observable_map.rs +++ b/crates/tests/libs/collections/tests/stock_observable_map.rs @@ -178,8 +178,7 @@ fn get_view() -> Result<()> { fn map_changed_event() -> Result<()> { let m = IObservableMap::::from(BTreeMap::from([(1, 10)])); - let events: std::sync::Arc)>>> = - std::sync::Arc::new(std::sync::Mutex::new(Vec::new())); + let events = std::sync::Arc::new(std::sync::Mutex::new(Vec::new())); let events_clone = events.clone(); let handler = diff --git a/crates/tests/libs/implement/tests/generic_default.rs b/crates/tests/libs/implement/tests/generic_default.rs index c72cd192328..11a2d2b36a6 100644 --- a/crates/tests/libs/implement/tests/generic_default.rs +++ b/crates/tests/libs/implement/tests/generic_default.rs @@ -27,8 +27,12 @@ where Ok(self.0.len() as u32) } - fn IndexOf(&self, value: Ref, result: &mut u32) -> Result { - match self.0.iter().position(|element| element == &*value) { + fn IndexOf(&self, value: Generic, result: &mut u32) -> Result { + match self + .0 + .iter() + .position(|element| element == generic_as_default::(&value)) + { Some(index) => { *result = index as u32; Ok(true) diff --git a/crates/tests/libs/implement/tests/generic_generic.rs b/crates/tests/libs/implement/tests/generic_generic.rs index 44f6b37f886..b29e5d04748 100644 --- a/crates/tests/libs/implement/tests/generic_generic.rs +++ b/crates/tests/libs/implement/tests/generic_generic.rs @@ -23,7 +23,7 @@ where panic!(); } - fn IndexOf(&self, _value: Ref, _index: &mut u32) -> Result { + fn IndexOf(&self, _value: Generic, _index: &mut u32) -> Result { panic!(); } diff --git a/crates/tests/libs/implement/tests/generic_primitive.rs b/crates/tests/libs/implement/tests/generic_primitive.rs index 877139aa09c..46551c22cc7 100644 --- a/crates/tests/libs/implement/tests/generic_primitive.rs +++ b/crates/tests/libs/implement/tests/generic_primitive.rs @@ -16,8 +16,8 @@ impl IVectorView_Impl for Thing_Impl { Ok(123) } - fn IndexOf(&self, value: Ref, index: &mut u32) -> Result { - *index = *value as u32; + fn IndexOf(&self, value: i32, index: &mut u32) -> Result { + *index = value as u32; Ok(true) } diff --git a/crates/tests/libs/implement/tests/generic_stringable.rs b/crates/tests/libs/implement/tests/generic_stringable.rs index c95289e0b1b..e99336d029c 100644 --- a/crates/tests/libs/implement/tests/generic_stringable.rs +++ b/crates/tests/libs/implement/tests/generic_stringable.rs @@ -16,7 +16,7 @@ impl IVectorView_Impl for Thing_Impl { panic!(); } - fn IndexOf(&self, _value: Ref, _index: &mut u32) -> Result { + fn IndexOf(&self, _value: Generic, _index: &mut u32) -> Result { panic!(); } diff --git a/crates/tests/libs/implement/tests/map.rs b/crates/tests/libs/implement/tests/map.rs index e63859268e6..690306d1ad2 100644 --- a/crates/tests/libs/implement/tests/map.rs +++ b/crates/tests/libs/implement/tests/map.rs @@ -42,11 +42,10 @@ impl IIterator_Impl> for Iterator_Impl { struct MapView(); impl IMapView_Impl for MapView_Impl { - // TODO: shouldn't require `Ref` for primitive - fn HasKey(&self, _key: Ref) -> Result { + fn HasKey(&self, _key: i32) -> Result { Ok(true) } - fn Lookup(&self, _key: Ref) -> Result { + fn Lookup(&self, _key: i32) -> Result { Ok(0.0) } fn Split( @@ -80,16 +79,16 @@ impl IMap_Impl for Map_Impl { fn GetView(&self) -> Result> { Ok(MapView().into()) } - fn HasKey(&self, _key: Ref) -> Result { + fn HasKey(&self, _key: i32) -> Result { Ok(true) } - fn Insert(&self, _key: Ref, _value: Ref) -> Result { + fn Insert(&self, _key: i32, _value: f32) -> Result { Ok(true) } - fn Lookup(&self, _key: Ref) -> Result { + fn Lookup(&self, _key: i32) -> Result { Ok(0.0) } - fn Remove(&self, _key: Ref) -> Result<()> { + fn Remove(&self, _key: i32) -> Result<()> { Ok(()) } fn Size(&self) -> Result { diff --git a/crates/tests/libs/implement/tests/vector.rs b/crates/tests/libs/implement/tests/vector.rs index a907136f7a3..1217038c469 100644 --- a/crates/tests/libs/implement/tests/vector.rs +++ b/crates/tests/libs/implement/tests/vector.rs @@ -48,9 +48,12 @@ where let reader = self.0.read().unwrap(); Ok(reader.len() as u32) } - fn IndexOf(&self, value: Ref, result: &mut u32) -> Result { + fn IndexOf(&self, value: Generic, result: &mut u32) -> Result { let reader = self.0.read().unwrap(); - match reader.iter().position(|element| element == &*value) { + match reader + .iter() + .position(|element| element == generic_as_default::(&value)) + { Some(index) => { *result = index as u32; Ok(true) @@ -77,16 +80,16 @@ where fn GetView(&self) -> Result> { Ok(self.to_interface()) } - fn IndexOf(&self, value: Ref, result: &mut u32) -> Result { + fn IndexOf(&self, value: Generic, result: &mut u32) -> Result { self.IndexOf(value, result) } - fn SetAt(&self, index: u32, value: Ref) -> Result<()> { + fn SetAt(&self, index: u32, value: Generic) -> Result<()> { let mut writer = self.0.write().unwrap(); let item = writer.get_mut(index as usize).ok_or_else(err_bounds)?; - *item = value.clone(); + *item = generic_as_default::(&value).clone(); Ok(()) } - fn InsertAt(&self, index: u32, value: Ref) -> Result<()> { + fn InsertAt(&self, index: u32, value: Generic) -> Result<()> { let mut writer = self.0.write().unwrap(); let index = index as usize; if index > writer.len() { @@ -94,7 +97,7 @@ where } else { let len = writer.len(); writer.try_reserve(len + 1).map_err(|_| err_memory())?; - writer.insert(index, value.clone()); + writer.insert(index, generic_as_default::(&value).clone()); Ok(()) } } @@ -108,11 +111,11 @@ where Err(err_bounds()) } } - fn Append(&self, value: Ref) -> Result<()> { + fn Append(&self, value: Generic) -> Result<()> { let mut writer = self.0.write().unwrap(); let len = writer.len(); writer.try_reserve(len + 1).map_err(|_| err_memory())?; - writer.insert(len, value.clone()); + writer.insert(len, generic_as_default::(&value).clone()); Ok(()) } fn RemoveAtEnd(&self) -> Result<()> { @@ -154,7 +157,7 @@ where fn Size(&self) -> Result { self.Size() } - fn IndexOf(&self, value: Ref, result: &mut u32) -> Result { + fn IndexOf(&self, value: Generic, result: &mut u32) -> Result { self.IndexOf(value, result) } fn GetMany(&self, startindex: u32, items: &mut [T::Default]) -> Result { diff --git a/crates/tests/winrt/event_core/tests/tests.rs b/crates/tests/winrt/event_core/tests/tests.rs index 06b964766c4..d042a239850 100644 --- a/crates/tests/winrt/event_core/tests/tests.rs +++ b/crates/tests/winrt/event_core/tests/tests.rs @@ -14,7 +14,7 @@ fn add_remove() -> Result<()> { // Add event handler. event.add(&EventHandler::::new(move |_, args| { - check_sender.store(*args, Ordering::Relaxed); + check_sender.store(args, Ordering::Relaxed); Ok(()) }))?; @@ -57,7 +57,7 @@ fn multiple() -> Result<()> { assert_eq!(c_check.load(Ordering::Relaxed), 0); let a_token = event.add(&EventHandler::::new(move |_, args| { - a_check_sender.store(*args, Ordering::Relaxed); + a_check_sender.store(args, Ordering::Relaxed); Ok(()) }))?; @@ -70,7 +70,7 @@ fn multiple() -> Result<()> { assert_eq!(c_check.load(Ordering::Relaxed), 0); let b_token = event.add(&EventHandler::::new(move |_, args| { - b_check_sender.store(*args, Ordering::Relaxed); + b_check_sender.store(args, Ordering::Relaxed); Ok(()) }))?; @@ -83,7 +83,7 @@ fn multiple() -> Result<()> { assert_eq!(c_check.load(Ordering::Relaxed), 0); let c_token = event.add(&EventHandler::::new(move |_, args| { - c_check_sender.store(*args, Ordering::Relaxed); + c_check_sender.store(args, Ordering::Relaxed); Ok(()) }))?; diff --git a/crates/tests/winrt/events_client/src/lib.rs b/crates/tests/winrt/events_client/src/lib.rs index 3852bf201d8..d2cf924a48e 100644 --- a/crates/tests/winrt/events_client/src/lib.rs +++ b/crates/tests/winrt/events_client/src/lib.rs @@ -14,9 +14,9 @@ fn test() -> Result<()> { assert_eq!(0, class.Signal(1)?); let token = class.Event(&TypedEventHandler::new( - move |sender: Ref, args: Ref| { + move |sender: Ref, args: i32| { assert_eq!(sender.as_ref().unwrap(), class); - assert_eq!(*args, 2); + assert_eq!(args, 2); Ok(()) }, ))?; @@ -26,17 +26,17 @@ fn test() -> Result<()> { assert_eq!(0, class.Signal(3)?); class.Event(&TypedEventHandler::new( - move |sender: Ref, args: Ref| { + move |sender: Ref, args: i32| { assert_eq!(sender.as_ref().unwrap(), class); - assert_eq!(*args, 4); + assert_eq!(args, 4); Ok(()) }, ))?; class.Event(&TypedEventHandler::new( - move |sender: Ref, args: Ref| { + move |sender: Ref, args: i32| { assert_eq!(sender.as_ref().unwrap(), class); - assert_eq!(*args, 4); + assert_eq!(args, 4); Ok(()) }, ))?; @@ -50,7 +50,7 @@ fn test_static() -> Result<()> { assert_eq!(0, Class::StaticSignal(1)?); let token = Class::StaticEvent(&EventHandler::new(move |_, args| { - assert_eq!(*args, 2); + assert_eq!(args, 2); Ok(()) }))?; @@ -59,12 +59,12 @@ fn test_static() -> Result<()> { assert_eq!(0, Class::StaticSignal(3)?); Class::StaticEvent(&EventHandler::new(move |_, args| { - assert_eq!(*args, 4); + assert_eq!(args, 4); Ok(()) }))?; Class::StaticEvent(&EventHandler::new(move |_, args| { - assert_eq!(*args, 4); + assert_eq!(args, 4); Ok(()) }))?; diff --git a/crates/tests/winrt/reference_custom/src/bindings.rs b/crates/tests/winrt/reference_custom/src/bindings.rs index 8a8b8eabaf7..90aeff26fea 100644 --- a/crates/tests/winrt/reference_custom/src/bindings.rs +++ b/crates/tests/winrt/reference_custom/src/bindings.rs @@ -935,11 +935,15 @@ where { fn GetAt(&self, index: u32) -> windows_core::Result; fn Size(&self) -> windows_core::Result; - fn IndexOf(&self, value: windows_core::Ref, index: &mut u32) -> windows_core::Result; - fn SetAt(&self, index: u32, value: windows_core::Ref) -> windows_core::Result<()>; - fn InsertAt(&self, index: u32, value: windows_core::Ref) -> windows_core::Result<()>; + fn IndexOf( + &self, + value: windows_core::Generic, + index: &mut u32, + ) -> windows_core::Result; + fn SetAt(&self, index: u32, value: windows_core::Generic) -> windows_core::Result<()>; + fn InsertAt(&self, index: u32, value: windows_core::Generic) -> windows_core::Result<()>; fn RemoveAt(&self, index: u32) -> windows_core::Result<()>; - fn Append(&self, value: windows_core::Ref) -> windows_core::Result<()>; + fn Append(&self, value: windows_core::Generic) -> windows_core::Result<()>; fn RemoveAtEnd(&self) -> windows_core::Result<()>; fn Clear(&self) -> windows_core::Result<()>; fn GetMany( diff --git a/crates/tests/winrt/reference_no_deps/src/bindings.rs b/crates/tests/winrt/reference_no_deps/src/bindings.rs index 2e456ecdf4d..f88b7f05d87 100644 --- a/crates/tests/winrt/reference_no_deps/src/bindings.rs +++ b/crates/tests/winrt/reference_no_deps/src/bindings.rs @@ -1002,11 +1002,15 @@ where { fn GetAt(&self, index: u32) -> windows_core::Result; fn Size(&self) -> windows_core::Result; - fn IndexOf(&self, value: windows_core::Ref, index: &mut u32) -> windows_core::Result; - fn SetAt(&self, index: u32, value: windows_core::Ref) -> windows_core::Result<()>; - fn InsertAt(&self, index: u32, value: windows_core::Ref) -> windows_core::Result<()>; + fn IndexOf( + &self, + value: windows_core::Generic, + index: &mut u32, + ) -> windows_core::Result; + fn SetAt(&self, index: u32, value: windows_core::Generic) -> windows_core::Result<()>; + fn InsertAt(&self, index: u32, value: windows_core::Generic) -> windows_core::Result<()>; fn RemoveAt(&self, index: u32) -> windows_core::Result<()>; - fn Append(&self, value: windows_core::Ref) -> windows_core::Result<()>; + fn Append(&self, value: windows_core::Generic) -> windows_core::Result<()>; fn RemoveAtEnd(&self) -> windows_core::Result<()>; fn Clear(&self) -> windows_core::Result<()>; fn GetMany(