diff --git a/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs b/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs index 205a2e48e9..296b44c403 100644 --- a/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs @@ -76,14 +76,12 @@ where } } -impl TryFrom> for IIterable +impl From> for IIterable where T: windows_core::RuntimeType, T::Default: Clone, { - type Error = windows_core::Error; - fn try_from(values: Vec) -> windows_core::Result { - // TODO: should provide a fallible try_into or more explicit allocator - Ok(windows_core::ComObject::new(StockIterable { values }).into_interface()) + fn from(values: Vec) -> Self { + windows_core::ComObject::new(StockIterable { values }).into_interface() } } diff --git a/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs b/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs index c1ff6cdd35..5553a25657 100644 --- a/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs @@ -135,16 +135,14 @@ where } } -impl TryFrom> for IMapView +impl From> for IMapView where K: windows_core::RuntimeType, V: windows_core::RuntimeType, K::Default: Clone + Ord, V::Default: Clone, { - type Error = windows_core::Error; - fn try_from(map: std::collections::BTreeMap) -> windows_core::Result { - // TODO: should provide a fallible try_into or more explicit allocator - Ok(StockMapView { map }.into()) + fn from(map: std::collections::BTreeMap) -> Self { + StockMapView { map }.into() } } diff --git a/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs b/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs index 5021474323..6dc2077e2b 100644 --- a/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs @@ -105,14 +105,12 @@ where } } -impl TryFrom> for IVectorView +impl From> for IVectorView where T: windows_core::RuntimeType, T::Default: Clone + PartialEq, { - type Error = windows_core::Error; - fn try_from(values: Vec) -> windows_core::Result { - // TODO: should provide a fallible try_into or more explicit allocator - Ok(windows_core::ComObject::new(StockVectorView { values }).into_interface()) + fn from(values: Vec) -> Self { + windows_core::ComObject::new(StockVectorView { values }).into_interface() } } diff --git a/crates/tests/collections/tests/stock_iterable.rs b/crates/tests/collections/tests/stock_iterable.rs index fda766ac2f..115533497d 100644 --- a/crates/tests/collections/tests/stock_iterable.rs +++ b/crates/tests/collections/tests/stock_iterable.rs @@ -6,7 +6,7 @@ use windows::{core::*, Foundation::Collections::*, Foundation::*, Win32::Foundat fn calendar() -> Result<()> { use windows::Globalization::*; - let languages = IIterable::try_from(vec![HSTRING::from("he-IL"), HSTRING::from("ja-JP")])?; + let languages = IIterable::from(vec![HSTRING::from("he-IL"), HSTRING::from("ja-JP")]); let calendar = Calendar::CreateCalendar( &languages, &CalendarIdentifiers::Hebrew()?, @@ -23,7 +23,7 @@ fn calendar() -> Result<()> { #[test] fn primitive() -> Result<()> { - let able = IIterable::::try_from(vec![])?; + let able = IIterable::::from(vec![]); let iter = able.First()?; assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS); @@ -37,7 +37,7 @@ fn primitive() -> Result<()> { assert_eq!(iter.GetMany(&mut [0; 5])?, 0); - let able = IIterable::::try_from(vec![1, 2, 3])?; + let able = IIterable::::from(vec![1, 2, 3]); let iter = able.First()?; assert_eq!(iter.Current()?, 1); @@ -85,7 +85,7 @@ fn primitive() -> Result<()> { #[test] fn hstring() -> Result<()> { - let able = IIterable::::try_from(vec![])?; + let able = IIterable::::from(vec![]); let iter = able.First()?; assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS); @@ -101,11 +101,11 @@ fn hstring() -> Result<()> { values.resize_with(5, Default::default); assert_eq!(iter.GetMany(&mut values)?, 0); - let able = IIterable::::try_from(vec![ + let able = IIterable::::from(vec![ HSTRING::from("one"), HSTRING::from("two"), HSTRING::from("three"), - ])?; + ]); let iter = able.First()?; assert_eq!(&iter.Current()?, h!("one")); @@ -178,7 +178,7 @@ fn stringable(value: &str) -> IStringable { #[test] fn defaulted() -> Result<()> { - let able = IIterable::::try_from(vec![])?; + let able = IIterable::::from(vec![]); let iter = able.First()?; assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS); @@ -194,11 +194,11 @@ fn defaulted() -> Result<()> { values.resize(5, None); assert_eq!(iter.GetMany(&mut values)?, 0); - let able = IIterable::::try_from(vec![ + let able = IIterable::::from(vec![ Some(stringable("one")), Some(stringable("two")), Some(stringable("three")), - ])?; + ]); let iter = able.First()?; assert_eq!(iter.Current()?.ToString()?, "one"); diff --git a/crates/tests/collections/tests/stock_map_view.rs b/crates/tests/collections/tests/stock_map_view.rs index fa06fd8fa9..d9f2512156 100644 --- a/crates/tests/collections/tests/stock_map_view.rs +++ b/crates/tests/collections/tests/stock_map_view.rs @@ -5,7 +5,7 @@ use windows::{core::*, Foundation::Collections::*, Win32::Foundation::E_BOUNDS}; #[test] fn primitive() -> Result<()> { - let m = IMapView::::try_from(BTreeMap::from([]))?; + let m = IMapView::::from(BTreeMap::from([])); assert_eq!(m.Lookup(0).unwrap_err().code(), E_BOUNDS); assert_eq!(m.Size()?, 0); assert_eq!(m.HasKey(0)?, false); @@ -14,7 +14,7 @@ fn primitive() -> Result<()> { m.Split(&mut left, &mut right)?; let m = BTreeMap::from([(1, 10), (2, 20)]); - let m: IMapView = m.try_into()?; + let m: IMapView = m.into(); assert_eq!(m.Lookup(1i32)?, 10u64); assert_eq!(m.Lookup(2)?, 20); assert_eq!(m.Size()?, 2); @@ -29,7 +29,7 @@ fn primitive() -> Result<()> { #[test] fn primitive_iterator() -> Result<()> { - let able = IMapView::::try_from(BTreeMap::from([]))?; + let able = IMapView::::from(BTreeMap::from([])); let iter = able.First()?; assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS); @@ -45,7 +45,7 @@ fn primitive_iterator() -> Result<()> { values.resize_with(5, Default::default); assert_eq!(iter.GetMany(&mut values)?, 0); - let able = IMapView::::try_from(BTreeMap::from([(1, 10), (2, 20), (3, 30)]))?; + let able = IMapView::::from(BTreeMap::from([(1, 10), (2, 20), (3, 30)])); let iter = able.First()?; assert_eq!(iter.Current()?.Key()?, 1i32); @@ -112,7 +112,7 @@ where #[test] fn hstring() -> Result<()> { - let m = IMapView::::try_from(BTreeMap::new())?; + let m = IMapView::::from(BTreeMap::new()); assert_eq!(m.Lookup(h!("missing")).unwrap_err().code(), E_BOUNDS); assert_eq!(m.Size()?, 0); assert_eq!(m.HasKey(h!("missing"))?, false); @@ -120,7 +120,7 @@ fn hstring() -> Result<()> { let m = BTreeMap::from([("one".into(), 1), ("two".into(), 2)]); assert!(m.contains_key(h!("one"))); - let m = IMapView::::try_from(m)?; + let m = IMapView::::from(m); assert_eq!(m.Lookup(h!("one"))?, 1); assert_eq!(m.Lookup(h!("two"))?, 2); assert_eq!(m.Size()?, 2); diff --git a/crates/tests/collections/tests/stock_vector_view.rs b/crates/tests/collections/tests/stock_vector_view.rs index 67cc93b10c..c325beca05 100644 --- a/crates/tests/collections/tests/stock_vector_view.rs +++ b/crates/tests/collections/tests/stock_vector_view.rs @@ -4,13 +4,13 @@ use windows::{core::*, Foundation::Collections::*, Win32::Foundation::E_BOUNDS}; #[test] fn primitive() -> Result<()> { - let v = IVectorView::::try_from(vec![])?; + let v = IVectorView::::from(vec![]); assert_eq!(v.GetAt(0).unwrap_err().code(), E_BOUNDS); assert_eq!(v.Size()?, 0); assert_eq!(v.IndexOf(0, &mut 0)?, false); assert_eq!(v.GetMany(0, &mut [0; 5])?, 0); - let v = IVectorView::::try_from(vec![1, 2, 3])?; + let v = IVectorView::::from(vec![1, 2, 3]); assert_eq!(v.GetAt(0)?, 1); assert_eq!(v.GetAt(1)?, 2); assert_eq!(v.GetAt(2)?, 3); @@ -45,7 +45,7 @@ fn primitive() -> Result<()> { #[test] fn primitive_iterator() -> Result<()> { - let able = IVectorView::::try_from(vec![])?; + let able = IVectorView::::from(vec![]); let iter = able.First()?; assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS); @@ -59,7 +59,7 @@ fn primitive_iterator() -> Result<()> { assert_eq!(iter.GetMany(&mut [0; 5])?, 0); - let able = IVectorView::::try_from(vec![1, 2, 3])?; + let able = IVectorView::::from(vec![1, 2, 3]); let iter = able.First()?; assert_eq!(iter.Current()?, 1);