From 2dc47b87a462d759f70faa894230a13e5246f264 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 10:48:56 -0700 Subject: [PATCH 01/12] move includes to win/sys crates --- .../libs/bindgen/src/rust/extensions/mod.rs | 86 +- .../Win32/UI/WindowsAndMessaging/mod.rs | 9 +- .../UI/WindowsAndMessaging/WindowLong.rs | 0 .../Windows/Foundation/Collections/impl.rs | 354 +------ .../src/Windows/Foundation/Numerics/mod.rs | 913 +----------------- .../windows/src/Windows/Foundation/mod.rs | 11 +- .../src/Windows/Win32/Foundation/mod.rs | 292 +----- .../Windows/Win32/Networking/WinSock/mod.rs | 71 +- .../src/Windows/Win32/System/Com/mod.rs | 54 +- .../src/Windows/Win32/System/Rpc/mod.rs | 33 +- .../Win32/UI/WindowsAndMessaging/mod.rs | 9 +- crates/libs/windows/src/extensions.rs | 0 .../Foundation/Collections/Iterable.rs | 0 .../Foundation/Collections/MapView.rs | 0 .../Foundation/Collections/VectorView.rs | 0 .../Foundation/Numerics/Matrix3x2.rs | 0 .../Foundation/Numerics/Matrix4x4.rs | 0 .../includes}/Foundation/Numerics/Vector2.rs | 0 .../includes}/Foundation/Numerics/Vector3.rs | 0 .../includes}/Foundation/Numerics/Vector4.rs | 0 .../src/includes}/Foundation/TimeSpan.rs | 0 .../src/includes}/Win32/Foundation/BOOL.rs | 0 .../src/includes}/Win32/Foundation/BOOLEAN.rs | 0 .../includes}/Win32/Foundation/NTSTATUS.rs | 0 .../Win32/Foundation/VARIANT_BOOL.rs | 0 .../includes}/Win32/Foundation/WIN32_ERROR.rs | 0 .../Win32/Networking/WinSock/IN6_ADDR.rs | 0 .../Win32/Networking/WinSock/IN_ADDR.rs | 0 .../Win32/Networking/WinSock/SOCKADDR_IN.rs | 0 .../Win32/Networking/WinSock/SOCKADDR_IN6.rs | 0 .../Win32/Networking/WinSock/SOCKADDR_INET.rs | 0 .../includes}/Win32/System/Com/IDispatch.rs | 0 .../includes}/Win32/System/Rpc/RPC_STATUS.rs | 0 .../UI/WindowsAndMessaging/WindowLong.rs | 8 + crates/libs/windows/src/lib.rs | 2 + 35 files changed, 83 insertions(+), 1759 deletions(-) rename crates/libs/{bindgen/src/rust/extensions/mod => sys/src/includes}/Win32/UI/WindowsAndMessaging/WindowLong.rs (100%) create mode 100644 crates/libs/windows/src/extensions.rs rename crates/libs/{bindgen/src/rust/extensions/impl => windows/src/includes}/Foundation/Collections/Iterable.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/impl => windows/src/includes}/Foundation/Collections/MapView.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/impl => windows/src/includes}/Foundation/Collections/VectorView.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Foundation/Numerics/Matrix3x2.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Foundation/Numerics/Matrix4x4.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Foundation/Numerics/Vector2.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Foundation/Numerics/Vector3.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Foundation/Numerics/Vector4.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Foundation/TimeSpan.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Foundation/BOOL.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Foundation/BOOLEAN.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Foundation/NTSTATUS.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Foundation/VARIANT_BOOL.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Foundation/WIN32_ERROR.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Networking/WinSock/IN6_ADDR.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Networking/WinSock/IN_ADDR.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Networking/WinSock/SOCKADDR_IN.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Networking/WinSock/SOCKADDR_IN6.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/Networking/WinSock/SOCKADDR_INET.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/System/Com/IDispatch.rs (100%) rename crates/libs/{bindgen/src/rust/extensions/mod => windows/src/includes}/Win32/System/Rpc/RPC_STATUS.rs (100%) create mode 100644 crates/libs/windows/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index 3a42b9b452..0c686babe3 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -1,55 +1,69 @@ use super::*; +fn include_ext(relative_path: &str) -> TokenStream { + quote! { + core::include!( + core::concat!( + core::env!("CARGO_MANIFEST_DIR"), + "/src/includes/", + #relative_path + ) + ); + } +} + +fn include_exts(relative_paths: &[&str]) -> TokenStream { + relative_paths.iter().map(|&p| include_ext(p)).collect() +} + pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { if namespace == "Windows.Win32.UI.WindowsAndMessaging" { - return include_str!("mod/Win32/UI/WindowsAndMessaging/WindowLong.rs").into(); + return include_ext("Win32/UI/WindowsAndMessaging/WindowLong.rs"); } if writer.sys { - return "".into(); + return quote!(); } match namespace { - "Windows.Foundation.Numerics" => concat!( - include_str!("mod/Foundation/Numerics/Matrix3x2.rs"), - include_str!("mod/Foundation/Numerics/Matrix4x4.rs"), - include_str!("mod/Foundation/Numerics/Vector2.rs"), - include_str!("mod/Foundation/Numerics/Vector3.rs"), - include_str!("mod/Foundation/Numerics/Vector4.rs"), - ), - "Windows.Foundation" => concat!(include_str!("mod/Foundation/TimeSpan.rs"),), - "Windows.Win32.Foundation" => concat!( - include_str!("mod/Win32/Foundation/BOOL.rs"), - include_str!("mod/Win32/Foundation/BOOLEAN.rs"), - include_str!("mod/Win32/Foundation/NTSTATUS.rs"), - include_str!("mod/Win32/Foundation/VARIANT_BOOL.rs"), - include_str!("mod/Win32/Foundation/WIN32_ERROR.rs"), - ), - "Windows.Win32.Networking.WinSock" => concat!( - include_str!("mod/Win32/Networking/WinSock/IN_ADDR.rs"), - include_str!("mod/Win32/Networking/WinSock/IN6_ADDR.rs"), - include_str!("mod/Win32/Networking/WinSock/SOCKADDR_IN.rs"), - include_str!("mod/Win32/Networking/WinSock/SOCKADDR_IN6.rs"), - include_str!("mod/Win32/Networking/WinSock/SOCKADDR_INET.rs"), - ), - "Windows.Win32.System.Rpc" => include_str!("mod/Win32/System/Rpc/RPC_STATUS.rs"), - "Windows.Win32.System.Com" => include_str!("mod/Win32/System/Com/IDispatch.rs"), + "Windows.Foundation.Numerics" => include_exts(&[ + "Foundation/Numerics/Matrix3x2.rs", + "Foundation/Numerics/Matrix4x4.rs", + "Foundation/Numerics/Vector2.rs", + "Foundation/Numerics/Vector3.rs", + "Foundation/Numerics/Vector4.rs", + ]), + "Windows.Foundation" => include_ext("Foundation/TimeSpan.rs"), + "Windows.Win32.Foundation" => include_exts(&[ + "Win32/Foundation/BOOL.rs", + "Win32/Foundation/BOOLEAN.rs", + "Win32/Foundation/NTSTATUS.rs", + "Win32/Foundation/VARIANT_BOOL.rs", + "Win32/Foundation/WIN32_ERROR.rs", + ]), + "Windows.Win32.Networking.WinSock" => include_exts(&[ + "Win32/Networking/WinSock/IN_ADDR.rs", + "Win32/Networking/WinSock/IN6_ADDR.rs", + "Win32/Networking/WinSock/SOCKADDR_IN.rs", + "Win32/Networking/WinSock/SOCKADDR_IN6.rs", + "Win32/Networking/WinSock/SOCKADDR_INET.rs", + ]), + "Windows.Win32.System.Rpc" => include_ext("Win32/System/Rpc/RPC_STATUS.rs"), + "Windows.Win32.System.Com" => include_ext("Win32/System/Com/IDispatch.rs"), "Windows.Win32.UI.WindowsAndMessaging" => { - include_str!("mod/Win32/UI/WindowsAndMessaging/WindowLong.rs") + include_ext("Win32/UI/WindowsAndMessaging/WindowLong.rs") } - _ => "", + _ => quote!(), } - .into() } pub fn gen_impl(namespace: &str) -> TokenStream { match namespace { - "Windows.Foundation.Collections" => concat!( - include_str!("impl/Foundation/Collections/Iterable.rs"), - include_str!("impl/Foundation/Collections/MapView.rs"), - include_str!("impl/Foundation/Collections/VectorView.rs"), - ), - _ => "", + "Windows.Foundation.Collections" => include_exts(&[ + "impl/Foundation/Collections/Iterable.rs", + "impl/Foundation/Collections/MapView.rs", + "impl/Foundation/Collections/VectorView.rs", + ]), + _ => quote!(), } - .into() } diff --git a/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs b/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs index 27cf261a2e..8271e63984 100644 --- a/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs +++ b/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs @@ -3752,11 +3752,4 @@ pub type SENDASYNCPROC = Option; pub type WNDENUMPROC = Option super::super::Foundation::BOOL>; pub type WNDPROC = Option super::super::Foundation::LRESULT>; -#[cfg(target_pointer_width = "32")] -pub use GetWindowLongA as GetWindowLongPtrA; -#[cfg(target_pointer_width = "32")] -pub use GetWindowLongW as GetWindowLongPtrW; -#[cfg(target_pointer_width = "32")] -pub use SetWindowLongA as SetWindowLongPtrA; -#[cfg(target_pointer_width = "32")] -pub use SetWindowLongW as SetWindowLongPtrW; +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/UI/WindowsAndMessaging/WindowLong.rs")); diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/UI/WindowsAndMessaging/WindowLong.rs b/crates/libs/sys/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/UI/WindowsAndMessaging/WindowLong.rs rename to crates/libs/sys/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs diff --git a/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs b/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs index 5c6ae95935..a430afff17 100644 --- a/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs +++ b/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs @@ -828,354 +828,6 @@ impl IVectorView_Vtbl { iid == & as windows_core::Interface>::IID } } -#[windows_core::implement(IIterable)] -struct StockIterable -where - T: windows_core::RuntimeType + 'static, - T::Default: Clone, -{ - values: Vec, -} - -impl IIterable_Impl for StockIterable_Impl -where - T: windows_core::RuntimeType, - T::Default: Clone, -{ - fn First(&self) -> windows_core::Result> { - use windows_core::IUnknownImpl; - Ok(windows_core::ComObject::new(StockIterator { owner: self.to_object(), current: 0.into() }).into_interface()) - } -} - -#[windows_core::implement(IIterator)] -struct StockIterator -where - T: windows_core::RuntimeType + 'static, - T::Default: Clone, -{ - owner: windows_core::ComObject>, - current: std::sync::atomic::AtomicUsize, -} - -impl IIterator_Impl for StockIterator_Impl -where - T: windows_core::RuntimeType, - T::Default: Clone, -{ - fn Current(&self) -> windows_core::Result { - let owner: &StockIterable = &self.owner; - let current = self.current.load(std::sync::atomic::Ordering::Relaxed); - - if self.owner.values.len() > current { - T::from_default(&owner.values[current]) - } else { - Err(windows_core::Error::from(windows_core::imp::E_BOUNDS)) - } - } - - fn HasCurrent(&self) -> windows_core::Result { - let owner: &StockIterable = &self.owner; - let current = self.current.load(std::sync::atomic::Ordering::Relaxed); - - Ok(owner.values.len() > current) - } - - fn MoveNext(&self) -> windows_core::Result { - let owner: &StockIterable = &self.owner; - let current = self.current.load(std::sync::atomic::Ordering::Relaxed); - - if current < owner.values.len() { - self.current.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - } - - Ok(owner.values.len() > current + 1) - } - - fn GetMany(&self, values: &mut [T::Default]) -> windows_core::Result { - let owner: &StockIterable = &self.owner; - let current = self.current.load(std::sync::atomic::Ordering::Relaxed); - - let actual = std::cmp::min(owner.values.len() - current, values.len()); - let (values, _) = values.split_at_mut(actual); - values.clone_from_slice(&owner.values[current..current + actual]); - self.current.fetch_add(actual, std::sync::atomic::Ordering::Relaxed); - Ok(actual as u32) - } -} - -impl TryFrom> 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()) - } -} -#[windows_core::implement(IMapView, IIterable>)] -struct StockMapView -where - K: windows_core::RuntimeType + 'static, - V: windows_core::RuntimeType + 'static, - K::Default: Clone + Ord, - V::Default: Clone, -{ - map: std::collections::BTreeMap, -} - -impl IIterable_Impl> for StockMapView_Impl -where - K: windows_core::RuntimeType, - V: windows_core::RuntimeType, - K::Default: Clone + Ord, - V::Default: Clone, -{ - fn First(&self) -> windows_core::Result>> { - use windows_core::IUnknownImpl; - - Ok(windows_core::ComObject::new(StockMapViewIterator:: { _owner: self.to_object(), current: std::sync::RwLock::new(self.map.iter()) }).into_interface()) - } -} - -impl IMapView_Impl for StockMapView_Impl -where - K: windows_core::RuntimeType, - V: windows_core::RuntimeType, - K::Default: Clone + Ord, - V::Default: Clone, -{ - fn Lookup(&self, key: &K::Default) -> windows_core::Result { - let value = self.map.get(key).ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?; - V::from_default(value) - } - fn Size(&self) -> windows_core::Result { - Ok(self.map.len().try_into()?) - } - fn HasKey(&self, key: &K::Default) -> windows_core::Result { - Ok(self.map.contains_key(key)) - } - fn Split(&self, first: &mut Option>, second: &mut Option>) -> windows_core::Result<()> { - *first = None; - *second = None; - Ok(()) - } -} - -#[windows_core::implement(IIterator>)] -struct StockMapViewIterator<'a, K, V> -where - K: windows_core::RuntimeType + 'static, - V: windows_core::RuntimeType + 'static, - K::Default: Clone + Ord, - V::Default: Clone, -{ - _owner: windows_core::ComObject>, - current: std::sync::RwLock>, -} - -impl<'a, K, V> IIterator_Impl> for StockMapViewIterator_Impl<'a, K, V> -where - K: windows_core::RuntimeType, - V: windows_core::RuntimeType, - K::Default: Clone + Ord, - V::Default: Clone, -{ - fn Current(&self) -> windows_core::Result> { - let mut current = self.current.read().unwrap().clone().peekable(); - - if let Some((key, value)) = current.peek() { - Ok(windows_core::ComObject::new(StockKeyValuePair { key: (*key).clone(), value: (*value).clone() }).into_interface()) - } else { - Err(windows_core::Error::from(windows_core::imp::E_BOUNDS)) - } - } - - fn HasCurrent(&self) -> windows_core::Result { - let mut current = self.current.read().unwrap().clone().peekable(); - - Ok(current.peek().is_some()) - } - - fn MoveNext(&self) -> windows_core::Result { - let mut current = self.current.write().unwrap(); - - current.next(); - Ok(current.clone().peekable().peek().is_some()) - } - - fn GetMany(&self, pairs: &mut [Option>]) -> windows_core::Result { - let mut current = self.current.write().unwrap(); - let mut actual = 0; - - for pair in pairs { - if let Some((key, value)) = current.next() { - *pair = Some(windows_core::ComObject::new(StockKeyValuePair { key: (*key).clone(), value: (*value).clone() }).into_interface()); - actual += 1; - } else { - break; - } - } - - Ok(actual) - } -} - -#[windows_core::implement(IKeyValuePair)] -struct StockKeyValuePair -where - K: windows_core::RuntimeType + 'static, - V: windows_core::RuntimeType + 'static, - K::Default: Clone, - V::Default: Clone, -{ - key: K::Default, - value: V::Default, -} - -impl IKeyValuePair_Impl for StockKeyValuePair_Impl -where - K: windows_core::RuntimeType, - V: windows_core::RuntimeType, - K::Default: Clone, - V::Default: Clone, -{ - fn Key(&self) -> windows_core::Result { - K::from_default(&self.key) - } - fn Value(&self) -> windows_core::Result { - V::from_default(&self.value) - } -} - -impl TryFrom> 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()) - } -} -#[windows_core::implement(IVectorView, IIterable)] -struct StockVectorView -where - T: windows_core::RuntimeType + 'static, - T::Default: Clone + PartialEq, -{ - values: Vec, -} - -impl IIterable_Impl for StockVectorView_Impl -where - T: windows_core::RuntimeType, - T::Default: Clone + PartialEq, -{ - fn First(&self) -> windows_core::Result> { - use windows_core::IUnknownImpl; - - Ok(windows_core::ComObject::new(StockVectorViewIterator { owner: self.to_object(), current: 0.into() }).into_interface()) - } -} - -impl IVectorView_Impl for StockVectorView_Impl -where - T: windows_core::RuntimeType, - T::Default: Clone + PartialEq, -{ - fn GetAt(&self, index: u32) -> windows_core::Result { - let item = self.values.get(index as usize).ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?; - T::from_default(item) - } - fn Size(&self) -> windows_core::Result { - Ok(self.values.len().try_into()?) - } - fn IndexOf(&self, value: &T::Default, result: &mut u32) -> windows_core::Result { - match self.values.iter().position(|element| element == value) { - Some(index) => { - *result = index as u32; - Ok(true) - } - None => Ok(false), - } - } - fn GetMany(&self, current: u32, values: &mut [T::Default]) -> windows_core::Result { - let current = current as usize; - if current >= self.values.len() { - return Ok(0); - } - let actual = std::cmp::min(self.values.len() - current, values.len()); - let (values, _) = values.split_at_mut(actual); - values.clone_from_slice(&self.values[current..current + actual]); - Ok(actual as u32) - } -} - -#[windows_core::implement(IIterator)] -struct StockVectorViewIterator -where - T: windows_core::RuntimeType + 'static, - T::Default: Clone + PartialEq, -{ - owner: windows_core::ComObject>, - current: std::sync::atomic::AtomicUsize, -} - -impl IIterator_Impl for StockVectorViewIterator_Impl -where - T: windows_core::RuntimeType, - T::Default: Clone + PartialEq, -{ - fn Current(&self) -> windows_core::Result { - let current = self.current.load(std::sync::atomic::Ordering::Relaxed); - - if let Some(item) = self.owner.values.get(current) { - T::from_default(item) - } else { - Err(windows_core::Error::from(windows_core::imp::E_BOUNDS)) - } - } - - fn HasCurrent(&self) -> windows_core::Result { - let current = self.current.load(std::sync::atomic::Ordering::Relaxed); - Ok(self.owner.values.len() > current) - } - - fn MoveNext(&self) -> windows_core::Result { - let current = self.current.load(std::sync::atomic::Ordering::Relaxed); - - if current < self.owner.values.len() { - self.current.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - } - - Ok(self.owner.values.len() > current + 1) - } - - fn GetMany(&self, values: &mut [T::Default]) -> windows_core::Result { - let current = self.current.load(std::sync::atomic::Ordering::Relaxed); - - let actual = std::cmp::min(self.owner.values.len() - current, values.len()); - let (values, _) = values.split_at_mut(actual); - values.clone_from_slice(&self.owner.values[current..current + actual]); - self.current.fetch_add(actual, std::sync::atomic::Ordering::Relaxed); - Ok(actual as u32) - } -} - -impl TryFrom> 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()) - } -} +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "impl/Foundation/Collections/Iterable.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "impl/Foundation/Collections/MapView.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "impl/Foundation/Collections/VectorView.rs")); diff --git a/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs b/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs index a2746505e1..e4ce26e57d 100644 --- a/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs @@ -157,911 +157,8 @@ impl Default for Vector4 { unsafe { core::mem::zeroed() } } } -impl Matrix3x2 { - pub const fn identity() -> Self { - Self { M11: 1.0, M12: 0.0, M21: 0.0, M22: 1.0, M31: 0.0, M32: 0.0 } - } - pub const fn translation(x: f32, y: f32) -> Self { - Self { M11: 1.0, M12: 0.0, M21: 0.0, M22: 1.0, M31: x, M32: y } - } - pub fn rotation(angle: f32, x: f32, y: f32) -> Self { - #[repr(C)] - pub struct D2D_POINT_2F { - pub x: f32, - pub y: f32, - } - windows_targets::link!("d2d1.dll" "system" fn D2D1MakeRotateMatrix(angle: f32, center: D2D_POINT_2F, matrix: *mut Matrix3x2)); - let mut matrix = Self::default(); - unsafe { - D2D1MakeRotateMatrix(angle, D2D_POINT_2F { x, y }, &mut matrix); - } - matrix - } - fn impl_add(&self, rhs: &Self) -> Self { - Self { - M11: self.M11 + rhs.M11, - M12: self.M12 + rhs.M12, - M21: self.M21 + rhs.M21, - M22: self.M22 + rhs.M22, - M31: self.M31 + rhs.M31, - M32: self.M32 + rhs.M32, - } - } - fn impl_sub(&self, rhs: &Self) -> Self { - Self { - M11: self.M11 - rhs.M11, - M12: self.M12 - rhs.M12, - M21: self.M21 - rhs.M21, - M22: self.M22 - rhs.M22, - M31: self.M31 - rhs.M31, - M32: self.M32 - rhs.M32, - } - } - fn impl_mul(&self, rhs: &Self) -> Self { - Self { - M11: self.M11 * rhs.M11 + self.M12 * rhs.M21, - M12: self.M11 * rhs.M12 + self.M12 * rhs.M22, - M21: self.M21 * rhs.M11 + self.M22 * rhs.M21, - M22: self.M21 * rhs.M12 + self.M22 * rhs.M22, - M31: self.M31 * rhs.M11 + self.M32 * rhs.M21 + rhs.M31, - M32: self.M31 * rhs.M12 + self.M32 * rhs.M22 + rhs.M32, - } - } - fn impl_mul_f32(&self, rhs: f32) -> Self { - Self { M11: self.M11 * rhs, M12: self.M12 * rhs, M21: self.M21 * rhs, M22: self.M22 * rhs, M31: self.M31 * rhs, M32: self.M32 * rhs } - } -} - -impl core::ops::Add for Matrix3x2 { - type Output = Matrix3x2; - fn add(self, rhs: Matrix3x2) -> Matrix3x2 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Matrix3x2> for Matrix3x2 { - type Output = Matrix3x2; - fn add(self, rhs: &Matrix3x2) -> Matrix3x2 { - self.impl_add(rhs) - } -} -impl core::ops::Add for &Matrix3x2 { - type Output = Matrix3x2; - fn add(self, rhs: Matrix3x2) -> Matrix3x2 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Matrix3x2> for &Matrix3x2 { - type Output = Matrix3x2; - fn add(self, rhs: &Matrix3x2) -> Matrix3x2 { - self.impl_add(rhs) - } -} -impl core::ops::Sub for Matrix3x2 { - type Output = Matrix3x2; - fn sub(self, rhs: Matrix3x2) -> Matrix3x2 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Matrix3x2> for Matrix3x2 { - type Output = Matrix3x2; - fn sub(self, rhs: &Matrix3x2) -> Matrix3x2 { - self.impl_sub(rhs) - } -} -impl core::ops::Sub for &Matrix3x2 { - type Output = Matrix3x2; - fn sub(self, rhs: Matrix3x2) -> Matrix3x2 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Matrix3x2> for &Matrix3x2 { - type Output = Matrix3x2; - fn sub(self, rhs: &Matrix3x2) -> Matrix3x2 { - self.impl_sub(rhs) - } -} -impl core::ops::Mul for Matrix3x2 { - type Output = Matrix3x2; - fn mul(self, rhs: Matrix3x2) -> Matrix3x2 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Matrix3x2> for Matrix3x2 { - type Output = Matrix3x2; - fn mul(self, rhs: &Matrix3x2) -> Matrix3x2 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for &Matrix3x2 { - type Output = Matrix3x2; - fn mul(self, rhs: Matrix3x2) -> Matrix3x2 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Matrix3x2> for &Matrix3x2 { - type Output = Matrix3x2; - fn mul(self, rhs: &Matrix3x2) -> Matrix3x2 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for Matrix3x2 { - type Output = Matrix3x2; - fn mul(self, rhs: f32) -> Matrix3x2 { - self.impl_mul_f32(rhs) - } -} -impl core::ops::Mul for &Matrix3x2 { - type Output = Matrix3x2; - fn mul(self, rhs: f32) -> Matrix3x2 { - self.impl_mul_f32(rhs) - } -} -impl Matrix4x4 { - pub const fn translation(x: f32, y: f32, z: f32) -> Self { - Self { - M11: 1.0, - M12: 0.0, - M13: 0.0, - M14: 0.0, - M21: 0.0, - M22: 1.0, - M23: 0.0, - M24: 0.0, - M31: 0.0, - M32: 0.0, - M33: 1.0, - M34: 0.0, - M41: x, - M42: y, - M43: z, - M44: 1.0, - } - } - pub fn rotation_y(degree: f32) -> Self { - windows_targets::link!("d2d1.dll" "system" fn D2D1SinCos(angle: f32, sin: *mut f32, cos: *mut f32)); - let angle = degree * (3.141592654 / 180.0); - let mut sin = 0.0; - let mut cos = 0.0; - unsafe { - D2D1SinCos(angle, &mut sin, &mut cos); - } - Self { - M11: cos, - M12: 0.0, - M13: -sin, - M14: 0.0, - M21: 0.0, - M22: 1.0, - M23: 0.0, - M24: 0.0, - M31: sin, - M32: 0.0, - M33: cos, - M34: 0.0, - M41: 0.0, - M42: 0.0, - M43: 0.0, - M44: 1.0, - } - } - pub fn perspective_projection(depth: f32) -> Self { - let projection = if depth > 0.0 { -1.0 / depth } else { 0.0 }; - Self { - M11: 1.0, - M12: 0.0, - M13: 0.0, - M14: 0.0, - M21: 0.0, - M22: 1.0, - M23: 0.0, - M24: 0.0, - M31: 0.0, - M32: 0.0, - M33: 1.0, - M34: projection, - M41: 0.0, - M42: 0.0, - M43: 0.0, - M44: 1.0, - } - } - fn impl_add(&self, rhs: &Self) -> Self { - Self { - M11: self.M11 + rhs.M11, - M12: self.M12 + rhs.M12, - M13: self.M13 + rhs.M13, - M14: self.M14 + rhs.M14, - M21: self.M21 + rhs.M21, - M22: self.M22 + rhs.M22, - M23: self.M23 + rhs.M23, - M24: self.M24 + rhs.M24, - M31: self.M31 + rhs.M31, - M32: self.M32 + rhs.M32, - M33: self.M33 + rhs.M33, - M34: self.M34 + rhs.M34, - M41: self.M41 + rhs.M41, - M42: self.M42 + rhs.M42, - M43: self.M43 + rhs.M43, - M44: self.M44 + rhs.M44, - } - } - fn impl_sub(&self, rhs: &Self) -> Self { - Self { - M11: self.M11 - rhs.M11, - M12: self.M12 - rhs.M12, - M13: self.M13 - rhs.M13, - M14: self.M14 - rhs.M14, - M21: self.M21 - rhs.M21, - M22: self.M22 - rhs.M22, - M23: self.M23 - rhs.M23, - M24: self.M24 - rhs.M24, - M31: self.M31 - rhs.M31, - M32: self.M32 - rhs.M32, - M33: self.M33 - rhs.M33, - M34: self.M34 - rhs.M34, - M41: self.M41 - rhs.M41, - M42: self.M42 - rhs.M42, - M43: self.M43 - rhs.M43, - M44: self.M44 - rhs.M44, - } - } - fn impl_mul(&self, rhs: &Self) -> Self { - Self { - M11: self.M11 * rhs.M11 + self.M12 * rhs.M21 + self.M13 * rhs.M31 + self.M14 * rhs.M41, - M12: self.M11 * rhs.M12 + self.M12 * rhs.M22 + self.M13 * rhs.M32 + self.M14 * rhs.M42, - M13: self.M11 * rhs.M13 + self.M12 * rhs.M23 + self.M13 * rhs.M33 + self.M14 * rhs.M43, - M14: self.M11 * rhs.M14 + self.M12 * rhs.M24 + self.M13 * rhs.M34 + self.M14 * rhs.M44, - M21: self.M21 * rhs.M11 + self.M22 * rhs.M21 + self.M23 * rhs.M31 + self.M24 * rhs.M41, - M22: self.M21 * rhs.M12 + self.M22 * rhs.M22 + self.M23 * rhs.M32 + self.M24 * rhs.M42, - M23: self.M21 * rhs.M13 + self.M22 * rhs.M23 + self.M23 * rhs.M33 + self.M24 * rhs.M43, - M24: self.M21 * rhs.M14 + self.M22 * rhs.M24 + self.M23 * rhs.M34 + self.M24 * rhs.M44, - M31: self.M31 * rhs.M11 + self.M32 * rhs.M21 + self.M33 * rhs.M31 + self.M34 * rhs.M41, - M32: self.M31 * rhs.M12 + self.M32 * rhs.M22 + self.M33 * rhs.M32 + self.M34 * rhs.M42, - M33: self.M31 * rhs.M13 + self.M32 * rhs.M23 + self.M33 * rhs.M33 + self.M34 * rhs.M43, - M34: self.M31 * rhs.M14 + self.M32 * rhs.M24 + self.M33 * rhs.M34 + self.M34 * rhs.M44, - M41: self.M41 * rhs.M11 + self.M42 * rhs.M21 + self.M43 * rhs.M31 + self.M44 * rhs.M41, - M42: self.M41 * rhs.M12 + self.M42 * rhs.M22 + self.M43 * rhs.M32 + self.M44 * rhs.M42, - M43: self.M41 * rhs.M13 + self.M42 * rhs.M23 + self.M43 * rhs.M33 + self.M44 * rhs.M43, - M44: self.M41 * rhs.M14 + self.M42 * rhs.M24 + self.M43 * rhs.M34 + self.M44 * rhs.M44, - } - } - fn impl_mul_f32(&self, rhs: f32) -> Self { - Self { - M11: self.M11 * rhs, - M12: self.M12 * rhs, - M13: self.M13 * rhs, - M14: self.M14 * rhs, - M21: self.M21 * rhs, - M22: self.M22 * rhs, - M23: self.M23 * rhs, - M24: self.M24 * rhs, - M31: self.M31 * rhs, - M32: self.M32 * rhs, - M33: self.M33 * rhs, - M34: self.M34 * rhs, - M41: self.M41 * rhs, - M42: self.M42 * rhs, - M43: self.M43 * rhs, - M44: self.M44 * rhs, - } - } -} - -impl core::ops::Add for Matrix4x4 { - type Output = Matrix4x4; - fn add(self, rhs: Matrix4x4) -> Matrix4x4 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Matrix4x4> for Matrix4x4 { - type Output = Matrix4x4; - fn add(self, rhs: &Matrix4x4) -> Matrix4x4 { - self.impl_add(rhs) - } -} -impl core::ops::Add for &Matrix4x4 { - type Output = Matrix4x4; - fn add(self, rhs: Matrix4x4) -> Matrix4x4 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Matrix4x4> for &Matrix4x4 { - type Output = Matrix4x4; - fn add(self, rhs: &Matrix4x4) -> Matrix4x4 { - self.impl_add(rhs) - } -} -impl core::ops::Sub for Matrix4x4 { - type Output = Matrix4x4; - fn sub(self, rhs: Matrix4x4) -> Matrix4x4 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Matrix4x4> for Matrix4x4 { - type Output = Matrix4x4; - fn sub(self, rhs: &Matrix4x4) -> Matrix4x4 { - self.impl_sub(rhs) - } -} -impl core::ops::Sub for &Matrix4x4 { - type Output = Matrix4x4; - fn sub(self, rhs: Matrix4x4) -> Matrix4x4 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Matrix4x4> for &Matrix4x4 { - type Output = Matrix4x4; - fn sub(self, rhs: &Matrix4x4) -> Matrix4x4 { - self.impl_sub(rhs) - } -} -impl core::ops::Mul for Matrix4x4 { - type Output = Matrix4x4; - fn mul(self, rhs: Matrix4x4) -> Matrix4x4 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Matrix4x4> for Matrix4x4 { - type Output = Matrix4x4; - fn mul(self, rhs: &Matrix4x4) -> Matrix4x4 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for &Matrix4x4 { - type Output = Matrix4x4; - fn mul(self, rhs: Matrix4x4) -> Matrix4x4 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Matrix4x4> for &Matrix4x4 { - type Output = Matrix4x4; - fn mul(self, rhs: &Matrix4x4) -> Matrix4x4 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for Matrix4x4 { - type Output = Matrix4x4; - fn mul(self, rhs: f32) -> Matrix4x4 { - self.impl_mul_f32(rhs) - } -} -impl core::ops::Mul for &Matrix4x4 { - type Output = Matrix4x4; - fn mul(self, rhs: f32) -> Matrix4x4 { - self.impl_mul_f32(rhs) - } -} -impl Vector2 { - pub fn new(X: f32, Y: f32) -> Self { - Self { X, Y } - } - pub fn zero() -> Self { - Self { X: 0f32, Y: 0f32 } - } - pub fn one() -> Self { - Self { X: 1f32, Y: 1f32 } - } - pub fn unit_x() -> Self { - Self { X: 1.0, Y: 0.0 } - } - pub fn unit_y() -> Self { - Self { X: 0.0, Y: 1.0 } - } - pub fn dot(&self, rhs: &Self) -> f32 { - self.X * rhs.X + self.Y * rhs.Y - } - pub fn length_squared(&self) -> f32 { - self.dot(self) - } - pub fn length(&self) -> f32 { - self.length_squared().sqrt() - } - pub fn distance(&self, value: &Self) -> f32 { - (self - value).length() - } - pub fn distance_squared(&self, value: &Self) -> f32 { - (self - value).length_squared() - } - pub fn normalize(&self) -> Self { - self / self.length() - } - - fn impl_add(&self, rhs: &Self) -> Self { - Self { X: self.X + rhs.X, Y: self.Y + rhs.Y } - } - fn impl_sub(&self, rhs: &Self) -> Self { - Self { X: self.X - rhs.X, Y: self.Y - rhs.Y } - } - fn impl_div(&self, rhs: &Self) -> Self { - Self { X: self.X / rhs.X, Y: self.Y / rhs.Y } - } - fn impl_div_f32(&self, rhs: f32) -> Self { - Self { X: self.X / rhs, Y: self.Y / rhs } - } - fn impl_mul(&self, rhs: &Self) -> Self { - Self { X: self.X * rhs.X, Y: self.Y * rhs.Y } - } - fn impl_mul_f32(&self, rhs: f32) -> Self { - Self { X: self.X * rhs, Y: self.Y * rhs } - } -} - -impl core::ops::Add for Vector2 { - type Output = Vector2; - fn add(self, rhs: Vector2) -> Vector2 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Vector2> for Vector2 { - type Output = Vector2; - fn add(self, rhs: &Vector2) -> Vector2 { - self.impl_add(rhs) - } -} -impl core::ops::Add for &Vector2 { - type Output = Vector2; - fn add(self, rhs: Vector2) -> Vector2 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Vector2> for &Vector2 { - type Output = Vector2; - fn add(self, rhs: &Vector2) -> Vector2 { - self.impl_add(rhs) - } -} -impl core::ops::Sub for Vector2 { - type Output = Vector2; - fn sub(self, rhs: Vector2) -> Vector2 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Vector2> for Vector2 { - type Output = Vector2; - fn sub(self, rhs: &Vector2) -> Vector2 { - self.impl_sub(rhs) - } -} -impl core::ops::Sub for &Vector2 { - type Output = Vector2; - fn sub(self, rhs: Vector2) -> Vector2 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Vector2> for &Vector2 { - type Output = Vector2; - fn sub(self, rhs: &Vector2) -> Vector2 { - self.impl_sub(rhs) - } -} -impl core::ops::Div for Vector2 { - type Output = Vector2; - fn div(self, rhs: Vector2) -> Vector2 { - self.impl_div(&rhs) - } -} -impl core::ops::Div<&Vector2> for Vector2 { - type Output = Vector2; - fn div(self, rhs: &Vector2) -> Vector2 { - self.impl_div(rhs) - } -} -impl core::ops::Div for &Vector2 { - type Output = Vector2; - fn div(self, rhs: Vector2) -> Vector2 { - self.impl_div(&rhs) - } -} -impl core::ops::Div<&Vector2> for &Vector2 { - type Output = Vector2; - fn div(self, rhs: &Vector2) -> Vector2 { - self.impl_div(rhs) - } -} -impl core::ops::Div for Vector2 { - type Output = Vector2; - fn div(self, rhs: f32) -> Vector2 { - self.impl_div_f32(rhs) - } -} -impl core::ops::Div for &Vector2 { - type Output = Vector2; - fn div(self, rhs: f32) -> Vector2 { - self.impl_div_f32(rhs) - } -} -impl core::ops::Mul for Vector2 { - type Output = Vector2; - fn mul(self, rhs: Vector2) -> Vector2 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Vector2> for Vector2 { - type Output = Vector2; - fn mul(self, rhs: &Vector2) -> Vector2 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for &Vector2 { - type Output = Vector2; - fn mul(self, rhs: Vector2) -> Vector2 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Vector2> for &Vector2 { - type Output = Vector2; - fn mul(self, rhs: &Vector2) -> Vector2 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for Vector2 { - type Output = Vector2; - fn mul(self, rhs: f32) -> Vector2 { - self.impl_mul_f32(rhs) - } -} -impl core::ops::Mul for &Vector2 { - type Output = Vector2; - fn mul(self, rhs: f32) -> Vector2 { - self.impl_mul_f32(rhs) - } -} -impl Vector3 { - pub fn new(X: f32, Y: f32, Z: f32) -> Self { - Self { X, Y, Z } - } - pub fn zero() -> Self { - Self { X: 0f32, Y: 0f32, Z: 0f32 } - } - pub fn one() -> Self { - Self { X: 1f32, Y: 1f32, Z: 1f32 } - } - pub fn unit_x() -> Self { - Self { X: 1.0, Y: 0.0, Z: 0.0 } - } - pub fn unit_y() -> Self { - Self { X: 0.0, Y: 1.0, Z: 0.0 } - } - pub fn unit_z() -> Self { - Self { X: 0.0, Y: 0.0, Z: 1.0 } - } - pub fn dot(&self, rhs: &Self) -> f32 { - self.X * rhs.X + self.Y * rhs.Y + self.Z * rhs.Z - } - pub fn length_squared(&self) -> f32 { - self.dot(self) - } - pub fn length(&self) -> f32 { - self.length_squared().sqrt() - } - pub fn distance(&self, value: &Self) -> f32 { - (self - value).length() - } - pub fn distance_squared(&self, value: &Self) -> f32 { - (self - value).length_squared() - } - pub fn normalize(&self) -> Self { - self / self.length() - } - - fn impl_add(&self, rhs: &Self) -> Self { - Self { X: self.X + rhs.X, Y: self.Y + rhs.Y, Z: self.Z + rhs.Z } - } - fn impl_sub(&self, rhs: &Self) -> Self { - Self { X: self.X - rhs.X, Y: self.Y - rhs.Y, Z: self.Z - rhs.Z } - } - fn impl_div(&self, rhs: &Self) -> Self { - Self { X: self.X / rhs.X, Y: self.Y / rhs.Y, Z: self.Z / rhs.Z } - } - fn impl_div_f32(&self, rhs: f32) -> Self { - Self { X: self.X / rhs, Y: self.Y / rhs, Z: self.Z / rhs } - } - fn impl_mul(&self, rhs: &Self) -> Self { - Self { X: self.X * rhs.X, Y: self.Y * rhs.Y, Z: self.Z * rhs.Z } - } - fn impl_mul_f32(&self, rhs: f32) -> Self { - Self { X: self.X * rhs, Y: self.Y * rhs, Z: self.Z * rhs } - } -} - -impl core::ops::Add for Vector3 { - type Output = Vector3; - fn add(self, rhs: Vector3) -> Vector3 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Vector3> for Vector3 { - type Output = Vector3; - fn add(self, rhs: &Vector3) -> Vector3 { - self.impl_add(rhs) - } -} -impl core::ops::Add for &Vector3 { - type Output = Vector3; - fn add(self, rhs: Vector3) -> Vector3 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Vector3> for &Vector3 { - type Output = Vector3; - fn add(self, rhs: &Vector3) -> Vector3 { - self.impl_add(rhs) - } -} -impl core::ops::Sub for Vector3 { - type Output = Vector3; - fn sub(self, rhs: Vector3) -> Vector3 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Vector3> for Vector3 { - type Output = Vector3; - fn sub(self, rhs: &Vector3) -> Vector3 { - self.impl_sub(rhs) - } -} -impl core::ops::Sub for &Vector3 { - type Output = Vector3; - fn sub(self, rhs: Vector3) -> Vector3 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Vector3> for &Vector3 { - type Output = Vector3; - fn sub(self, rhs: &Vector3) -> Vector3 { - self.impl_sub(rhs) - } -} -impl core::ops::Div for Vector3 { - type Output = Vector3; - fn div(self, rhs: Vector3) -> Vector3 { - self.impl_div(&rhs) - } -} -impl core::ops::Div<&Vector3> for Vector3 { - type Output = Vector3; - fn div(self, rhs: &Vector3) -> Vector3 { - self.impl_div(rhs) - } -} -impl core::ops::Div for &Vector3 { - type Output = Vector3; - fn div(self, rhs: Vector3) -> Vector3 { - self.impl_div(&rhs) - } -} -impl core::ops::Div<&Vector3> for &Vector3 { - type Output = Vector3; - fn div(self, rhs: &Vector3) -> Vector3 { - self.impl_div(rhs) - } -} -impl core::ops::Div for Vector3 { - type Output = Vector3; - fn div(self, rhs: f32) -> Vector3 { - self.impl_div_f32(rhs) - } -} -impl core::ops::Div for &Vector3 { - type Output = Vector3; - fn div(self, rhs: f32) -> Vector3 { - self.impl_div_f32(rhs) - } -} -impl core::ops::Mul for Vector3 { - type Output = Vector3; - fn mul(self, rhs: Vector3) -> Vector3 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Vector3> for Vector3 { - type Output = Vector3; - fn mul(self, rhs: &Vector3) -> Vector3 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for &Vector3 { - type Output = Vector3; - fn mul(self, rhs: Vector3) -> Vector3 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Vector3> for &Vector3 { - type Output = Vector3; - fn mul(self, rhs: &Vector3) -> Vector3 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for Vector3 { - type Output = Vector3; - fn mul(self, rhs: f32) -> Vector3 { - self.impl_mul_f32(rhs) - } -} -impl core::ops::Mul for &Vector3 { - type Output = Vector3; - fn mul(self, rhs: f32) -> Vector3 { - self.impl_mul_f32(rhs) - } -} -impl Vector4 { - pub fn new(X: f32, Y: f32, Z: f32, W: f32) -> Self { - Self { X, Y, Z, W } - } - pub fn zero() -> Self { - Self { X: 0f32, Y: 0f32, Z: 0f32, W: 0f32 } - } - pub fn one() -> Self { - Self { X: 1f32, Y: 1f32, Z: 1f32, W: 1f32 } - } - pub fn unit_x() -> Self { - Self { X: 1.0, Y: 0.0, Z: 0.0, W: 0.0 } - } - pub fn unit_y() -> Self { - Self { X: 0.0, Y: 1.0, Z: 0.0, W: 0.0 } - } - pub fn unit_z() -> Self { - Self { X: 0.0, Y: 0.0, Z: 1.0, W: 0.0 } - } - pub fn unit_w() -> Self { - Self { X: 0.0, Y: 0.0, Z: 0.0, W: 1.0 } - } - pub fn dot(&self, rhs: &Self) -> f32 { - self.X * rhs.X + self.Y * rhs.Y + self.Z * rhs.Z + self.W * rhs.W - } - pub fn length_squared(&self) -> f32 { - self.dot(self) - } - pub fn length(&self) -> f32 { - self.length_squared().sqrt() - } - pub fn distance(&self, value: &Self) -> f32 { - (self - value).length() - } - pub fn distance_squared(&self, value: &Self) -> f32 { - (self - value).length_squared() - } - pub fn normalize(&self) -> Self { - self / self.length() - } - - fn impl_add(&self, rhs: &Self) -> Self { - Self { X: self.X + rhs.X, Y: self.Y + rhs.Y, Z: self.Z + rhs.Z, W: self.W + rhs.W } - } - fn impl_sub(&self, rhs: &Self) -> Self { - Self { X: self.X - rhs.X, Y: self.Y - rhs.Y, Z: self.Z - rhs.Z, W: self.W - rhs.W } - } - fn impl_div(&self, rhs: &Self) -> Self { - Self { X: self.X / rhs.X, Y: self.Y / rhs.Y, Z: self.Z / rhs.Z, W: self.W / rhs.W } - } - fn impl_div_f32(&self, rhs: f32) -> Self { - Self { X: self.X / rhs, Y: self.Y / rhs, Z: self.Z / rhs, W: self.W / rhs } - } - fn impl_mul(&self, rhs: &Self) -> Self { - Self { X: self.X * rhs.X, Y: self.Y * rhs.Y, Z: self.Z * rhs.Z, W: self.W * rhs.W } - } - fn impl_mul_f32(&self, rhs: f32) -> Self { - Self { X: self.X * rhs, Y: self.Y * rhs, Z: self.Z * rhs, W: self.W * rhs } - } -} - -impl core::ops::Add for Vector4 { - type Output = Vector4; - fn add(self, rhs: Vector4) -> Vector4 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Vector4> for Vector4 { - type Output = Vector4; - fn add(self, rhs: &Vector4) -> Vector4 { - self.impl_add(rhs) - } -} -impl core::ops::Add for &Vector4 { - type Output = Vector4; - fn add(self, rhs: Vector4) -> Vector4 { - self.impl_add(&rhs) - } -} -impl core::ops::Add<&Vector4> for &Vector4 { - type Output = Vector4; - fn add(self, rhs: &Vector4) -> Vector4 { - self.impl_add(rhs) - } -} -impl core::ops::Sub for Vector4 { - type Output = Vector4; - fn sub(self, rhs: Vector4) -> Vector4 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Vector4> for Vector4 { - type Output = Vector4; - fn sub(self, rhs: &Vector4) -> Vector4 { - self.impl_sub(rhs) - } -} -impl core::ops::Sub for &Vector4 { - type Output = Vector4; - fn sub(self, rhs: Vector4) -> Vector4 { - self.impl_sub(&rhs) - } -} -impl core::ops::Sub<&Vector4> for &Vector4 { - type Output = Vector4; - fn sub(self, rhs: &Vector4) -> Vector4 { - self.impl_sub(rhs) - } -} -impl core::ops::Div for Vector4 { - type Output = Vector4; - fn div(self, rhs: Vector4) -> Vector4 { - self.impl_div(&rhs) - } -} -impl core::ops::Div<&Vector4> for Vector4 { - type Output = Vector4; - fn div(self, rhs: &Vector4) -> Vector4 { - self.impl_div(rhs) - } -} -impl core::ops::Div for &Vector4 { - type Output = Vector4; - fn div(self, rhs: Vector4) -> Vector4 { - self.impl_div(&rhs) - } -} -impl core::ops::Div<&Vector4> for &Vector4 { - type Output = Vector4; - fn div(self, rhs: &Vector4) -> Vector4 { - self.impl_div(rhs) - } -} -impl core::ops::Div for Vector4 { - type Output = Vector4; - fn div(self, rhs: f32) -> Vector4 { - self.impl_div_f32(rhs) - } -} -impl core::ops::Div for &Vector4 { - type Output = Vector4; - fn div(self, rhs: f32) -> Vector4 { - self.impl_div_f32(rhs) - } -} -impl core::ops::Mul for Vector4 { - type Output = Vector4; - fn mul(self, rhs: Vector4) -> Vector4 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Vector4> for Vector4 { - type Output = Vector4; - fn mul(self, rhs: &Vector4) -> Vector4 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for &Vector4 { - type Output = Vector4; - fn mul(self, rhs: Vector4) -> Vector4 { - self.impl_mul(&rhs) - } -} -impl core::ops::Mul<&Vector4> for &Vector4 { - type Output = Vector4; - fn mul(self, rhs: &Vector4) -> Vector4 { - self.impl_mul(rhs) - } -} -impl core::ops::Mul for Vector4 { - type Output = Vector4; - fn mul(self, rhs: f32) -> Vector4 { - self.impl_mul_f32(rhs) - } -} -impl core::ops::Mul for &Vector4 { - type Output = Vector4; - fn mul(self, rhs: f32) -> Vector4 { - self.impl_mul_f32(rhs) - } -} +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Matrix3x2.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Matrix4x4.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Vector2.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Vector3.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Vector4.rs")); diff --git a/crates/libs/windows/src/Windows/Foundation/mod.rs b/crates/libs/windows/src/Windows/Foundation/mod.rs index f05aafbeff..72fa1ca913 100644 --- a/crates/libs/windows/src/Windows/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/mod.rs @@ -3216,15 +3216,6 @@ where pub TSender: core::marker::PhantomData, pub TResult: core::marker::PhantomData, } -impl From for TimeSpan { - fn from(value: core::time::Duration) -> Self { - Self { Duration: (value.as_nanos() / 100) as i64 } - } -} -impl From for core::time::Duration { - fn from(value: TimeSpan) -> Self { - core::time::Duration::from_nanos((value.Duration * 100) as u64) - } -} +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/TimeSpan.rs")); #[cfg(feature = "implement")] core::include!("impl.rs"); diff --git a/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs b/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs index 236dbdf461..fee9d39eec 100644 --- a/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs @@ -11088,290 +11088,8 @@ pub type FARPROC = Option isize>; pub type NEARPROC = Option isize>; pub type PAPCFUNC = Option; pub type PROC = Option isize>; -impl BOOL { - #[inline] - pub fn as_bool(self) -> bool { - self.0 != 0 - } - #[inline] - pub fn ok(self) -> windows_core::Result<()> { - if self.as_bool() { - Ok(()) - } else { - Err(windows_core::Error::from_win32()) - } - } - #[inline] - #[track_caller] - pub fn unwrap(self) { - self.ok().unwrap(); - } - #[inline] - #[track_caller] - pub fn expect(self, msg: &str) { - self.ok().expect(msg); - } -} -impl From for bool { - fn from(value: BOOL) -> Self { - value.as_bool() - } -} -impl From<&BOOL> for bool { - fn from(value: &BOOL) -> Self { - value.as_bool() - } -} -impl From for BOOL { - fn from(value: bool) -> Self { - if value { - Self(1) - } else { - Self(0) - } - } -} -impl From<&bool> for BOOL { - fn from(value: &bool) -> Self { - (*value).into() - } -} -impl PartialEq for BOOL { - fn eq(&self, other: &bool) -> bool { - self.as_bool() == *other - } -} -impl PartialEq for bool { - fn eq(&self, other: &BOOL) -> bool { - *self == other.as_bool() - } -} -impl core::ops::Not for BOOL { - type Output = Self; - fn not(self) -> Self::Output { - if self.as_bool() { - Self(0) - } else { - Self(1) - } - } -} -impl windows_core::Param for bool { - unsafe fn param(self) -> windows_core::ParamValue { - windows_core::ParamValue::Owned(self.into()) - } -} -impl BOOLEAN { - #[inline] - pub fn as_bool(self) -> bool { - self.0 != 0 - } - #[inline] - pub fn ok(self) -> windows_core::Result<()> { - if self.as_bool() { - Ok(()) - } else { - Err(windows_core::Error::from_win32()) - } - } - #[inline] - #[track_caller] - pub fn unwrap(self) { - self.ok().unwrap(); - } - #[inline] - #[track_caller] - pub fn expect(self, msg: &str) { - self.ok().expect(msg); - } -} -impl From for bool { - fn from(value: BOOLEAN) -> Self { - value.as_bool() - } -} -impl From<&BOOLEAN> for bool { - fn from(value: &BOOLEAN) -> Self { - value.as_bool() - } -} -impl From for BOOLEAN { - fn from(value: bool) -> Self { - if value { - Self(1) - } else { - Self(0) - } - } -} -impl From<&bool> for BOOLEAN { - fn from(value: &bool) -> Self { - (*value).into() - } -} -impl PartialEq for BOOLEAN { - fn eq(&self, other: &bool) -> bool { - self.as_bool() == *other - } -} -impl PartialEq for bool { - fn eq(&self, other: &BOOLEAN) -> bool { - *self == other.as_bool() - } -} -impl core::ops::Not for BOOLEAN { - type Output = Self; - fn not(self) -> Self::Output { - if self.as_bool() { - Self(0) - } else { - Self(1) - } - } -} -impl windows_core::Param for bool { - unsafe fn param(self) -> windows_core::ParamValue { - windows_core::ParamValue::Owned(self.into()) - } -} -impl NTSTATUS { - #[inline] - pub const fn is_ok(self) -> bool { - self.0 >= 0 - } - #[inline] - pub const fn is_err(self) -> bool { - !self.is_ok() - } - #[inline] - pub const fn to_hresult(self) -> windows_core::HRESULT { - windows_core::HRESULT::from_nt(self.0) - } - #[inline] - pub fn ok(self) -> windows_core::Result<()> { - if self.is_ok() { - Ok(()) - } else { - Err(self.to_hresult().into()) - } - } -} -impl From for windows_core::HRESULT { - fn from(value: NTSTATUS) -> Self { - value.to_hresult() - } -} -impl From for windows_core::Error { - fn from(value: NTSTATUS) -> Self { - value.to_hresult().into() - } -} -impl VARIANT_BOOL { - #[inline] - pub fn as_bool(self) -> bool { - self.0 != 0 - } - #[inline] - pub fn ok(self) -> windows_core::Result<()> { - if self.as_bool() { - Ok(()) - } else { - Err(windows_core::Error::from_win32()) - } - } - #[inline] - #[track_caller] - pub fn unwrap(self) { - self.ok().unwrap(); - } - #[inline] - #[track_caller] - pub fn expect(self, msg: &str) { - self.ok().expect(msg); - } -} -impl From for bool { - fn from(value: VARIANT_BOOL) -> Self { - value.as_bool() - } -} -impl From<&VARIANT_BOOL> for bool { - fn from(value: &VARIANT_BOOL) -> Self { - value.as_bool() - } -} -impl From for VARIANT_BOOL { - fn from(value: bool) -> Self { - if value { - VARIANT_TRUE - } else { - VARIANT_FALSE - } - } -} -impl From<&bool> for VARIANT_BOOL { - fn from(value: &bool) -> Self { - (*value).into() - } -} -impl PartialEq for VARIANT_BOOL { - fn eq(&self, other: &bool) -> bool { - self.as_bool() == *other - } -} -impl PartialEq for bool { - fn eq(&self, other: &VARIANT_BOOL) -> bool { - *self == other.as_bool() - } -} -impl core::ops::Not for VARIANT_BOOL { - type Output = Self; - fn not(self) -> Self::Output { - if self.as_bool() { - VARIANT_FALSE - } else { - VARIANT_TRUE - } - } -} -impl WIN32_ERROR { - #[inline] - pub const fn is_ok(self) -> bool { - self.0 == 0 - } - #[inline] - pub const fn is_err(self) -> bool { - !self.is_ok() - } - #[inline] - pub const fn to_hresult(self) -> windows_core::HRESULT { - windows_core::HRESULT::from_win32(self.0) - } - #[inline] - pub fn from_error(error: &windows_core::Error) -> Option { - let hresult = error.code().0 as u32; - if ((hresult >> 16) & 0x7FF) == 7 { - Some(Self(hresult & 0xFFFF)) - } else { - None - } - } - #[inline] - pub fn ok(self) -> windows_core::Result<()> { - if self.is_ok() { - Ok(()) - } else { - Err(self.to_hresult().into()) - } - } -} -impl From for windows_core::HRESULT { - fn from(value: WIN32_ERROR) -> Self { - value.to_hresult() - } -} -impl From for windows_core::Error { - fn from(value: WIN32_ERROR) -> Self { - value.to_hresult().into() - } -} +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/BOOL.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/BOOLEAN.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/NTSTATUS.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/VARIANT_BOOL.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/WIN32_ERROR.rs")); diff --git a/crates/libs/windows/src/Windows/Win32/Networking/WinSock/mod.rs b/crates/libs/windows/src/Windows/Win32/Networking/WinSock/mod.rs index 249838db0b..3001c0db6d 100644 --- a/crates/libs/windows/src/Windows/Win32/Networking/WinSock/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/Networking/WinSock/mod.rs @@ -9395,69 +9395,8 @@ pub type LPWSPSOCKET = Option i32>; pub type LPWSPSTRINGTOADDRESS = Option i32>; -impl From for IN_ADDR { - fn from(addr: std::net::Ipv4Addr) -> Self { - // u32::from(addr) is in host byte order - // S_addr must be big-endian, network byte order - Self { S_un: IN_ADDR_0 { S_addr: u32::from(addr).to_be() } } - } -} -impl From for std::net::Ipv4Addr { - fn from(in_addr: IN_ADDR) -> Self { - // SAFETY: this is safe because the union variants are just views of the same exact data - // in_addr.S_un.S_addr is big-endian, network byte order - // Ipv4Addr::new() expects the parameter in host byte order - Self::from(u32::from_be(unsafe { in_addr.S_un.S_addr })) - } -} -impl From for IN6_ADDR { - fn from(addr: std::net::Ipv6Addr) -> Self { - Self { u: IN6_ADDR_0 { Byte: addr.octets() } } - } -} -impl From for std::net::Ipv6Addr { - fn from(in6_addr: IN6_ADDR) -> Self { - // SAFETY: this is safe because the union variants are just views of the same exact data - Self::from(unsafe { in6_addr.u.Byte }) - } -} -impl From for SOCKADDR_IN { - fn from(addr: std::net::SocketAddrV4) -> Self { - // addr.port() is in host byte order - // sin_port must be big-endian, network byte order - SOCKADDR_IN { sin_family: AF_INET, sin_port: addr.port().to_be(), sin_addr: (*addr.ip()).into(), ..Default::default() } - } -} -impl From for SOCKADDR_IN6 { - fn from(addr: std::net::SocketAddrV6) -> Self { - // addr.port() and addr.flowinfo() are in host byte order - // sin6_port and sin6_flowinfo must be big-endian, network byte order - // sin6_scope_id is a bitfield without endianness - SOCKADDR_IN6 { - sin6_family: AF_INET6, - sin6_port: addr.port().to_be(), - sin6_flowinfo: addr.flowinfo().to_be(), - sin6_addr: (*addr.ip()).into(), - Anonymous: SOCKADDR_IN6_0 { sin6_scope_id: addr.scope_id() }, - ..Default::default() - } - } -} -impl From for SOCKADDR_INET { - fn from(addr: std::net::SocketAddrV4) -> Self { - SOCKADDR_INET { Ipv4: addr.into() } - } -} -impl From for SOCKADDR_INET { - fn from(addr: std::net::SocketAddrV6) -> Self { - SOCKADDR_INET { Ipv6: addr.into() } - } -} -impl From for SOCKADDR_INET { - fn from(addr: std::net::SocketAddr) -> Self { - match addr { - std::net::SocketAddr::V4(socket_addr_v4) => socket_addr_v4.into(), - std::net::SocketAddr::V6(socket_addr_v6) => socket_addr_v6.into(), - } - } -} +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/IN_ADDR.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/IN6_ADDR.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/SOCKADDR_IN.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/SOCKADDR_IN6.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/SOCKADDR_INET.rs")); diff --git a/crates/libs/windows/src/Windows/Win32/System/Com/mod.rs b/crates/libs/windows/src/Windows/Win32/System/Com/mod.rs index 03ff5c386f..14b61c13e4 100644 --- a/crates/libs/windows/src/Windows/Win32/System/Com/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/System/Com/mod.rs @@ -7664,58 +7664,6 @@ pub type LPEXCEPFINO_DEFERRED_FILLIN = Option windows_core::HRESULT>; pub type LPFNGETCLASSOBJECT = Option windows_core::HRESULT>; pub type PFNCONTEXTCALL = Option windows_core::HRESULT>; -impl From for windows_core::VARIANT { - fn from(value: IDispatch) -> Self { - unsafe { - Self::from_raw(windows_core::imp::VARIANT { - Anonymous: windows_core::imp::VARIANT_0 { - Anonymous: windows_core::imp::VARIANT_0_0 { vt: 9, wReserved1: 0, wReserved2: 0, wReserved3: 0, Anonymous: windows_core::imp::VARIANT_0_0_0 { pdispVal: core::mem::transmute(value) } }, - }, - }) - } - } -} - -impl From for windows_core::PROPVARIANT { - fn from(value: IDispatch) -> Self { - unsafe { - Self::from_raw(windows_core::imp::PROPVARIANT { - Anonymous: windows_core::imp::PROPVARIANT_0 { - Anonymous: windows_core::imp::PROPVARIANT_0_0 { vt: 9, wReserved1: 0, wReserved2: 0, wReserved3: 0, Anonymous: windows_core::imp::PROPVARIANT_0_0_0 { pdispVal: core::mem::transmute(value) } }, - }, - }) - } - } -} - -impl TryFrom<&windows_core::VARIANT> for IDispatch { - type Error = windows_core::Error; - fn try_from(from: &windows_core::VARIANT) -> windows_core::Result { - let from = from.as_raw(); - unsafe { - if from.Anonymous.Anonymous.vt == 9 && !from.Anonymous.Anonymous.Anonymous.pdispVal.is_null() { - let dispatch: &IDispatch = core::mem::transmute(&from.Anonymous.Anonymous.Anonymous.pdispVal); - Ok(dispatch.clone()) - } else { - Err(windows_core::Error::from_hresult(windows_core::imp::TYPE_E_TYPEMISMATCH)) - } - } - } -} - -impl TryFrom<&windows_core::PROPVARIANT> for IDispatch { - type Error = windows_core::Error; - fn try_from(from: &windows_core::PROPVARIANT) -> windows_core::Result { - let from = from.as_raw(); - unsafe { - if from.Anonymous.Anonymous.vt == 9 && !from.Anonymous.Anonymous.Anonymous.pdispVal.is_null() { - let dispatch: &IDispatch = core::mem::transmute(&from.Anonymous.Anonymous.Anonymous.pdispVal); - Ok(dispatch.clone()) - } else { - Err(windows_core::Error::from_hresult(windows_core::imp::TYPE_E_TYPEMISMATCH)) - } - } - } -} +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/System/Com/IDispatch.rs")); #[cfg(feature = "implement")] core::include!("impl.rs"); diff --git a/crates/libs/windows/src/Windows/Win32/System/Rpc/mod.rs b/crates/libs/windows/src/Windows/Win32/System/Rpc/mod.rs index 7a57c16013..f674fdb692 100644 --- a/crates/libs/windows/src/Windows/Win32/System/Rpc/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/System/Rpc/mod.rs @@ -7088,35 +7088,4 @@ pub type USER_MARSHAL_SIZING_ROUTINE = Option *mut u8>; #[cfg(feature = "Win32_System_Com")] pub type XMIT_HELPER_ROUTINE = Option; -impl RPC_STATUS { - #[inline] - pub const fn is_ok(self) -> bool { - self.0 == 0 - } - #[inline] - pub const fn is_err(self) -> bool { - !self.is_ok() - } - #[inline] - pub const fn to_hresult(self) -> windows_core::HRESULT { - windows_core::HRESULT::from_win32(self.0 as u32) - } - #[inline] - pub fn ok(self) -> windows_core::Result<()> { - if self.is_ok() { - Ok(()) - } else { - Err(self.to_hresult().into()) - } - } -} -impl From for windows_core::HRESULT { - fn from(value: RPC_STATUS) -> Self { - value.to_hresult() - } -} -impl From for windows_core::Error { - fn from(value: RPC_STATUS) -> Self { - value.to_hresult().into() - } -} +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/System/Rpc/RPC_STATUS.rs")); diff --git a/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs b/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs index edb22e7e01..f56e256e79 100644 --- a/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs @@ -9426,11 +9426,4 @@ pub type SENDASYNCPROC = Option; pub type WNDENUMPROC = Option super::super::Foundation::BOOL>; pub type WNDPROC = Option super::super::Foundation::LRESULT>; -#[cfg(target_pointer_width = "32")] -pub use GetWindowLongA as GetWindowLongPtrA; -#[cfg(target_pointer_width = "32")] -pub use GetWindowLongW as GetWindowLongPtrW; -#[cfg(target_pointer_width = "32")] -pub use SetWindowLongA as SetWindowLongPtrA; -#[cfg(target_pointer_width = "32")] -pub use SetWindowLongW as SetWindowLongPtrW; +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/UI/WindowsAndMessaging/WindowLong.rs")); diff --git a/crates/libs/windows/src/extensions.rs b/crates/libs/windows/src/extensions.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/Iterable.rs b/crates/libs/windows/src/includes/Foundation/Collections/Iterable.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/Iterable.rs rename to crates/libs/windows/src/includes/Foundation/Collections/Iterable.rs diff --git a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/MapView.rs b/crates/libs/windows/src/includes/Foundation/Collections/MapView.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/MapView.rs rename to crates/libs/windows/src/includes/Foundation/Collections/MapView.rs diff --git a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/VectorView.rs b/crates/libs/windows/src/includes/Foundation/Collections/VectorView.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/VectorView.rs rename to crates/libs/windows/src/includes/Foundation/Collections/VectorView.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Matrix3x2.rs b/crates/libs/windows/src/includes/Foundation/Numerics/Matrix3x2.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Matrix3x2.rs rename to crates/libs/windows/src/includes/Foundation/Numerics/Matrix3x2.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Matrix4x4.rs b/crates/libs/windows/src/includes/Foundation/Numerics/Matrix4x4.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Matrix4x4.rs rename to crates/libs/windows/src/includes/Foundation/Numerics/Matrix4x4.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector2.rs b/crates/libs/windows/src/includes/Foundation/Numerics/Vector2.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector2.rs rename to crates/libs/windows/src/includes/Foundation/Numerics/Vector2.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector3.rs b/crates/libs/windows/src/includes/Foundation/Numerics/Vector3.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector3.rs rename to crates/libs/windows/src/includes/Foundation/Numerics/Vector3.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector4.rs b/crates/libs/windows/src/includes/Foundation/Numerics/Vector4.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector4.rs rename to crates/libs/windows/src/includes/Foundation/Numerics/Vector4.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Foundation/TimeSpan.rs b/crates/libs/windows/src/includes/Foundation/TimeSpan.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/TimeSpan.rs rename to crates/libs/windows/src/includes/Foundation/TimeSpan.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/BOOL.rs b/crates/libs/windows/src/includes/Win32/Foundation/BOOL.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/BOOL.rs rename to crates/libs/windows/src/includes/Win32/Foundation/BOOL.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/BOOLEAN.rs b/crates/libs/windows/src/includes/Win32/Foundation/BOOLEAN.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/BOOLEAN.rs rename to crates/libs/windows/src/includes/Win32/Foundation/BOOLEAN.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/NTSTATUS.rs b/crates/libs/windows/src/includes/Win32/Foundation/NTSTATUS.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/NTSTATUS.rs rename to crates/libs/windows/src/includes/Win32/Foundation/NTSTATUS.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/VARIANT_BOOL.rs b/crates/libs/windows/src/includes/Win32/Foundation/VARIANT_BOOL.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/VARIANT_BOOL.rs rename to crates/libs/windows/src/includes/Win32/Foundation/VARIANT_BOOL.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/WIN32_ERROR.rs b/crates/libs/windows/src/includes/Win32/Foundation/WIN32_ERROR.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/WIN32_ERROR.rs rename to crates/libs/windows/src/includes/Win32/Foundation/WIN32_ERROR.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/IN6_ADDR.rs b/crates/libs/windows/src/includes/Win32/Networking/WinSock/IN6_ADDR.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/IN6_ADDR.rs rename to crates/libs/windows/src/includes/Win32/Networking/WinSock/IN6_ADDR.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/IN_ADDR.rs b/crates/libs/windows/src/includes/Win32/Networking/WinSock/IN_ADDR.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/IN_ADDR.rs rename to crates/libs/windows/src/includes/Win32/Networking/WinSock/IN_ADDR.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/SOCKADDR_IN.rs b/crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/SOCKADDR_IN.rs rename to crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/SOCKADDR_IN6.rs b/crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN6.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/SOCKADDR_IN6.rs rename to crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN6.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/SOCKADDR_INET.rs b/crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_INET.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Networking/WinSock/SOCKADDR_INET.rs rename to crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_INET.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/System/Com/IDispatch.rs b/crates/libs/windows/src/includes/Win32/System/Com/IDispatch.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/System/Com/IDispatch.rs rename to crates/libs/windows/src/includes/Win32/System/Com/IDispatch.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/System/Rpc/RPC_STATUS.rs b/crates/libs/windows/src/includes/Win32/System/Rpc/RPC_STATUS.rs similarity index 100% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/System/Rpc/RPC_STATUS.rs rename to crates/libs/windows/src/includes/Win32/System/Rpc/RPC_STATUS.rs diff --git a/crates/libs/windows/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs b/crates/libs/windows/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs new file mode 100644 index 0000000000..d98a5511a5 --- /dev/null +++ b/crates/libs/windows/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs @@ -0,0 +1,8 @@ +#[cfg(target_pointer_width = "32")] +pub use GetWindowLongA as GetWindowLongPtrA; +#[cfg(target_pointer_width = "32")] +pub use GetWindowLongW as GetWindowLongPtrW; +#[cfg(target_pointer_width = "32")] +pub use SetWindowLongA as SetWindowLongPtrA; +#[cfg(target_pointer_width = "32")] +pub use SetWindowLongW as SetWindowLongPtrW; diff --git a/crates/libs/windows/src/lib.rs b/crates/libs/windows/src/lib.rs index 3072303ccc..9cb770d101 100644 --- a/crates/libs/windows/src/lib.rs +++ b/crates/libs/windows/src/lib.rs @@ -17,4 +17,6 @@ extern crate self as windows; pub use windows_core as core; +mod extensions; + include!("Windows/mod.rs"); From ce5f9c551242d73b85be7618a5210a650f937375 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 11:02:26 -0700 Subject: [PATCH 02/12] move bool types to real modules --- crates/libs/windows/src/Windows/Foundation/mod.rs | 1 - crates/libs/windows/src/Windows/Win32/Foundation/mod.rs | 5 ----- crates/libs/windows/src/extensions.rs | 9 +++++++++ crates/libs/windows/src/extensions/Foundation.rs | 1 + .../src/{includes => extensions}/Foundation/TimeSpan.rs | 2 ++ crates/libs/windows/src/extensions/Win32.rs | 2 ++ crates/libs/windows/src/extensions/Win32/Foundation.rs | 5 +++++ .../{includes => extensions}/Win32/Foundation/BOOL.rs | 2 ++ .../{includes => extensions}/Win32/Foundation/BOOLEAN.rs | 2 ++ .../Win32/Foundation/NTSTATUS.rs | 2 ++ .../Win32/Foundation/VARIANT_BOOL.rs | 2 ++ .../Win32/Foundation/WIN32_ERROR.rs | 2 ++ crates/libs/windows/src/lib.rs | 3 ++- 13 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 crates/libs/windows/src/extensions/Foundation.rs rename crates/libs/windows/src/{includes => extensions}/Foundation/TimeSpan.rs (90%) create mode 100644 crates/libs/windows/src/extensions/Win32.rs create mode 100644 crates/libs/windows/src/extensions/Win32/Foundation.rs rename crates/libs/windows/src/{includes => extensions}/Win32/Foundation/BOOL.rs (97%) rename crates/libs/windows/src/{includes => extensions}/Win32/Foundation/BOOLEAN.rs (97%) rename crates/libs/windows/src/{includes => extensions}/Win32/Foundation/NTSTATUS.rs (94%) rename crates/libs/windows/src/{includes => extensions}/Win32/Foundation/VARIANT_BOOL.rs (95%) rename crates/libs/windows/src/{includes => extensions}/Win32/Foundation/WIN32_ERROR.rs (95%) diff --git a/crates/libs/windows/src/Windows/Foundation/mod.rs b/crates/libs/windows/src/Windows/Foundation/mod.rs index 72fa1ca913..1ba0d86d51 100644 --- a/crates/libs/windows/src/Windows/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/mod.rs @@ -3216,6 +3216,5 @@ where pub TSender: core::marker::PhantomData, pub TResult: core::marker::PhantomData, } -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/TimeSpan.rs")); #[cfg(feature = "implement")] core::include!("impl.rs"); diff --git a/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs b/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs index fee9d39eec..8630dbd1d6 100644 --- a/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs @@ -11088,8 +11088,3 @@ pub type FARPROC = Option isize>; pub type NEARPROC = Option isize>; pub type PAPCFUNC = Option; pub type PROC = Option isize>; -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/BOOL.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/BOOLEAN.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/NTSTATUS.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/VARIANT_BOOL.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Foundation/WIN32_ERROR.rs")); diff --git a/crates/libs/windows/src/extensions.rs b/crates/libs/windows/src/extensions.rs index e69de29bb2..7e8d8c5f34 100644 --- a/crates/libs/windows/src/extensions.rs +++ b/crates/libs/windows/src/extensions.rs @@ -0,0 +1,9 @@ +//! Contains extensions to the generated bindings +//! +//! This module contains code that extends the functionality of the bindings generated by `bindgen`. +//! It adds inherent impls, trait impls, etc. + +#[cfg(feature = "Foundation")] +pub mod Foundation; +#[cfg(feature = "Win32")] +pub mod Win32; diff --git a/crates/libs/windows/src/extensions/Foundation.rs b/crates/libs/windows/src/extensions/Foundation.rs new file mode 100644 index 0000000000..14dc7df636 --- /dev/null +++ b/crates/libs/windows/src/extensions/Foundation.rs @@ -0,0 +1 @@ +pub mod TimeSpan; diff --git a/crates/libs/windows/src/includes/Foundation/TimeSpan.rs b/crates/libs/windows/src/extensions/Foundation/TimeSpan.rs similarity index 90% rename from crates/libs/windows/src/includes/Foundation/TimeSpan.rs rename to crates/libs/windows/src/extensions/Foundation/TimeSpan.rs index 510fd18a53..6fb2fd69b5 100644 --- a/crates/libs/windows/src/includes/Foundation/TimeSpan.rs +++ b/crates/libs/windows/src/extensions/Foundation/TimeSpan.rs @@ -1,3 +1,5 @@ +use crate::Foundation::TimeSpan; + impl From for TimeSpan { fn from(value: core::time::Duration) -> Self { Self { Duration: (value.as_nanos() / 100) as i64 } diff --git a/crates/libs/windows/src/extensions/Win32.rs b/crates/libs/windows/src/extensions/Win32.rs new file mode 100644 index 0000000000..9a6da9527b --- /dev/null +++ b/crates/libs/windows/src/extensions/Win32.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "Win32_Foundation")] +pub mod Foundation; diff --git a/crates/libs/windows/src/extensions/Win32/Foundation.rs b/crates/libs/windows/src/extensions/Win32/Foundation.rs new file mode 100644 index 0000000000..0008cd07fb --- /dev/null +++ b/crates/libs/windows/src/extensions/Win32/Foundation.rs @@ -0,0 +1,5 @@ +pub mod BOOL; +pub mod BOOLEAN; +pub mod NTSTATUS; +pub mod VARIANT_BOOL; +pub mod WIN32_ERROR; diff --git a/crates/libs/windows/src/includes/Win32/Foundation/BOOL.rs b/crates/libs/windows/src/extensions/Win32/Foundation/BOOL.rs similarity index 97% rename from crates/libs/windows/src/includes/Win32/Foundation/BOOL.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/BOOL.rs index 60cfd39fca..42bc5d9f00 100644 --- a/crates/libs/windows/src/includes/Win32/Foundation/BOOL.rs +++ b/crates/libs/windows/src/extensions/Win32/Foundation/BOOL.rs @@ -1,3 +1,5 @@ +use crate::Win32::Foundation::BOOL; + impl BOOL { #[inline] pub fn as_bool(self) -> bool { diff --git a/crates/libs/windows/src/includes/Win32/Foundation/BOOLEAN.rs b/crates/libs/windows/src/extensions/Win32/Foundation/BOOLEAN.rs similarity index 97% rename from crates/libs/windows/src/includes/Win32/Foundation/BOOLEAN.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/BOOLEAN.rs index 7f6a9cc20d..43dd9dffed 100644 --- a/crates/libs/windows/src/includes/Win32/Foundation/BOOLEAN.rs +++ b/crates/libs/windows/src/extensions/Win32/Foundation/BOOLEAN.rs @@ -1,3 +1,5 @@ +use crate::Win32::Foundation::BOOLEAN; + impl BOOLEAN { #[inline] pub fn as_bool(self) -> bool { diff --git a/crates/libs/windows/src/includes/Win32/Foundation/NTSTATUS.rs b/crates/libs/windows/src/extensions/Win32/Foundation/NTSTATUS.rs similarity index 94% rename from crates/libs/windows/src/includes/Win32/Foundation/NTSTATUS.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/NTSTATUS.rs index 2ec25a8cef..2d40cf001f 100644 --- a/crates/libs/windows/src/includes/Win32/Foundation/NTSTATUS.rs +++ b/crates/libs/windows/src/extensions/Win32/Foundation/NTSTATUS.rs @@ -1,3 +1,5 @@ +use crate::Win32::Foundation::NTSTATUS; + impl NTSTATUS { #[inline] pub const fn is_ok(self) -> bool { diff --git a/crates/libs/windows/src/includes/Win32/Foundation/VARIANT_BOOL.rs b/crates/libs/windows/src/extensions/Win32/Foundation/VARIANT_BOOL.rs similarity index 95% rename from crates/libs/windows/src/includes/Win32/Foundation/VARIANT_BOOL.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/VARIANT_BOOL.rs index 2505030176..628e022e2c 100644 --- a/crates/libs/windows/src/includes/Win32/Foundation/VARIANT_BOOL.rs +++ b/crates/libs/windows/src/extensions/Win32/Foundation/VARIANT_BOOL.rs @@ -1,3 +1,5 @@ +use crate::Win32::Foundation::{VARIANT_BOOL, VARIANT_TRUE, VARIANT_FALSE}; + impl VARIANT_BOOL { #[inline] pub fn as_bool(self) -> bool { diff --git a/crates/libs/windows/src/includes/Win32/Foundation/WIN32_ERROR.rs b/crates/libs/windows/src/extensions/Win32/Foundation/WIN32_ERROR.rs similarity index 95% rename from crates/libs/windows/src/includes/Win32/Foundation/WIN32_ERROR.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/WIN32_ERROR.rs index 3b0579b354..91ee28549a 100644 --- a/crates/libs/windows/src/includes/Win32/Foundation/WIN32_ERROR.rs +++ b/crates/libs/windows/src/extensions/Win32/Foundation/WIN32_ERROR.rs @@ -1,3 +1,5 @@ +use crate::Win32::Foundation::WIN32_ERROR; + impl WIN32_ERROR { #[inline] pub const fn is_ok(self) -> bool { diff --git a/crates/libs/windows/src/lib.rs b/crates/libs/windows/src/lib.rs index 9cb770d101..7d50b11534 100644 --- a/crates/libs/windows/src/lib.rs +++ b/crates/libs/windows/src/lib.rs @@ -17,6 +17,7 @@ extern crate self as windows; pub use windows_core as core; -mod extensions; +#[doc(hidden)] +pub mod extensions; include!("Windows/mod.rs"); From a9efbe3767c97508927d64b6d7b1c46cb41fb9ad Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 13:00:28 -0700 Subject: [PATCH 03/12] move WindowLong extensions --- crates/libs/bindgen/src/rust/extensions/mod.rs | 15 --------------- .../Windows/Win32/UI/WindowsAndMessaging/mod.rs | 1 - .../Windows/Win32/UI/WindowsAndMessaging/mod.rs | 1 - .../Win32/UI/WindowsAndMessaging/WindowLong.rs | 0 4 files changed, 17 deletions(-) rename crates/libs/windows/src/{includes => extensions}/Win32/UI/WindowsAndMessaging/WindowLong.rs (100%) diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index 0c686babe3..ba72c4a3e3 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -17,10 +17,6 @@ fn include_exts(relative_paths: &[&str]) -> TokenStream { } pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { - if namespace == "Windows.Win32.UI.WindowsAndMessaging" { - return include_ext("Win32/UI/WindowsAndMessaging/WindowLong.rs"); - } - if writer.sys { return quote!(); } @@ -33,14 +29,6 @@ pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { "Foundation/Numerics/Vector3.rs", "Foundation/Numerics/Vector4.rs", ]), - "Windows.Foundation" => include_ext("Foundation/TimeSpan.rs"), - "Windows.Win32.Foundation" => include_exts(&[ - "Win32/Foundation/BOOL.rs", - "Win32/Foundation/BOOLEAN.rs", - "Win32/Foundation/NTSTATUS.rs", - "Win32/Foundation/VARIANT_BOOL.rs", - "Win32/Foundation/WIN32_ERROR.rs", - ]), "Windows.Win32.Networking.WinSock" => include_exts(&[ "Win32/Networking/WinSock/IN_ADDR.rs", "Win32/Networking/WinSock/IN6_ADDR.rs", @@ -50,9 +38,6 @@ pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { ]), "Windows.Win32.System.Rpc" => include_ext("Win32/System/Rpc/RPC_STATUS.rs"), "Windows.Win32.System.Com" => include_ext("Win32/System/Com/IDispatch.rs"), - "Windows.Win32.UI.WindowsAndMessaging" => { - include_ext("Win32/UI/WindowsAndMessaging/WindowLong.rs") - } _ => quote!(), } } diff --git a/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs b/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs index 8271e63984..2e7b089f75 100644 --- a/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs +++ b/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs @@ -3752,4 +3752,3 @@ pub type SENDASYNCPROC = Option; pub type WNDENUMPROC = Option super::super::Foundation::BOOL>; pub type WNDPROC = Option super::super::Foundation::LRESULT>; -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/UI/WindowsAndMessaging/WindowLong.rs")); diff --git a/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs b/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs index f56e256e79..c8900118b1 100644 --- a/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs @@ -9426,4 +9426,3 @@ pub type SENDASYNCPROC = Option; pub type WNDENUMPROC = Option super::super::Foundation::BOOL>; pub type WNDPROC = Option super::super::Foundation::LRESULT>; -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/UI/WindowsAndMessaging/WindowLong.rs")); diff --git a/crates/libs/windows/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs b/crates/libs/windows/src/extensions/Win32/UI/WindowsAndMessaging/WindowLong.rs similarity index 100% rename from crates/libs/windows/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs rename to crates/libs/windows/src/extensions/Win32/UI/WindowsAndMessaging/WindowLong.rs From 1dbc334fef5570d44481ee3d95cc4a1de42c3d23 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 13:22:59 -0700 Subject: [PATCH 04/12] move Collections --- crates/libs/bindgen/src/rust/extensions/mod.rs | 6 +----- .../libs/windows/src/Windows/Foundation/Collections/impl.rs | 4 +--- crates/libs/windows/src/extensions/Foundation.rs | 4 ++++ .../libs/windows/src/extensions/Foundation/Collections.rs | 3 +++ .../Foundation/Collections/Iterable.rs | 2 ++ .../Foundation/Collections/MapView.rs | 2 ++ .../Foundation/Collections/VectorView.rs | 2 ++ crates/libs/windows/src/includes/Foundation/Collections.rs | 1 + 8 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 crates/libs/windows/src/extensions/Foundation/Collections.rs rename crates/libs/windows/src/{includes => extensions}/Foundation/Collections/Iterable.rs (96%) rename crates/libs/windows/src/{includes => extensions}/Foundation/Collections/MapView.rs (97%) rename crates/libs/windows/src/{includes => extensions}/Foundation/Collections/VectorView.rs (97%) create mode 100644 crates/libs/windows/src/includes/Foundation/Collections.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index ba72c4a3e3..491b3cd0ba 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -44,11 +44,7 @@ pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { pub fn gen_impl(namespace: &str) -> TokenStream { match namespace { - "Windows.Foundation.Collections" => include_exts(&[ - "impl/Foundation/Collections/Iterable.rs", - "impl/Foundation/Collections/MapView.rs", - "impl/Foundation/Collections/VectorView.rs", - ]), + "Windows.Foundation.Collections" => include_ext("Foundation/Collections.rs"), _ => quote!(), } } diff --git a/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs b/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs index a430afff17..d1acb045d5 100644 --- a/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs +++ b/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs @@ -828,6 +828,4 @@ impl IVectorView_Vtbl { iid == & as windows_core::Interface>::IID } } -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "impl/Foundation/Collections/Iterable.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "impl/Foundation/Collections/MapView.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "impl/Foundation/Collections/VectorView.rs")); +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Collections.rs")); diff --git a/crates/libs/windows/src/extensions/Foundation.rs b/crates/libs/windows/src/extensions/Foundation.rs index 14dc7df636..265a054e93 100644 --- a/crates/libs/windows/src/extensions/Foundation.rs +++ b/crates/libs/windows/src/extensions/Foundation.rs @@ -1 +1,5 @@ +#[cfg(feature = "Foundation_Collections")] +pub mod Collections; + pub mod TimeSpan; + diff --git a/crates/libs/windows/src/extensions/Foundation/Collections.rs b/crates/libs/windows/src/extensions/Foundation/Collections.rs new file mode 100644 index 0000000000..4405f57e0f --- /dev/null +++ b/crates/libs/windows/src/extensions/Foundation/Collections.rs @@ -0,0 +1,3 @@ +pub mod Iterable; +pub mod MapView; +pub mod VectorView; diff --git a/crates/libs/windows/src/includes/Foundation/Collections/Iterable.rs b/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs similarity index 96% rename from crates/libs/windows/src/includes/Foundation/Collections/Iterable.rs rename to crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs index 3a1854cfa4..8731fa22d3 100644 --- a/crates/libs/windows/src/includes/Foundation/Collections/Iterable.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs @@ -1,3 +1,5 @@ +use crate::Foundation::Collections::{IIterable, IIterable_Impl, IIterator, IIterator_Impl}; + #[windows_core::implement(IIterable)] struct StockIterable where diff --git a/crates/libs/windows/src/includes/Foundation/Collections/MapView.rs b/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs similarity index 97% rename from crates/libs/windows/src/includes/Foundation/Collections/MapView.rs rename to crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs index eca599138d..7d709a84d9 100644 --- a/crates/libs/windows/src/includes/Foundation/Collections/MapView.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs @@ -1,3 +1,5 @@ +use crate::Foundation::Collections::{IIterable, IIterable_Impl, IIterator, IIterator_Impl, IKeyValuePair, IKeyValuePair_Impl, IMapView, IMapView_Impl}; + #[windows_core::implement(IMapView, IIterable>)] struct StockMapView where diff --git a/crates/libs/windows/src/includes/Foundation/Collections/VectorView.rs b/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs similarity index 97% rename from crates/libs/windows/src/includes/Foundation/Collections/VectorView.rs rename to crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs index 94de4e5d05..53b13f97af 100644 --- a/crates/libs/windows/src/includes/Foundation/Collections/VectorView.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs @@ -1,3 +1,5 @@ +use crate::Foundation::Collections::{IIterator, IIterator_Impl, IIterable, IIterable_Impl, IVectorView, IVectorView_Impl}; + #[windows_core::implement(IVectorView, IIterable)] struct StockVectorView where diff --git a/crates/libs/windows/src/includes/Foundation/Collections.rs b/crates/libs/windows/src/includes/Foundation/Collections.rs new file mode 100644 index 0000000000..4d678edc12 --- /dev/null +++ b/crates/libs/windows/src/includes/Foundation/Collections.rs @@ -0,0 +1 @@ +pub use crate::extensions::Foundation::Collections::*; From cea4d74dc3690e13cbfe7c7ad889fe66645ddfe0 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 13:31:38 -0700 Subject: [PATCH 05/12] move Win32_System_Com --- crates/libs/bindgen/src/rust/extensions/mod.rs | 1 - crates/libs/windows/src/Windows/Win32/System/Com/mod.rs | 1 - crates/libs/windows/src/extensions/Win32.rs | 3 +++ crates/libs/windows/src/extensions/Win32/System.rs | 2 ++ crates/libs/windows/src/extensions/Win32/System/Com.rs | 1 + .../src/{includes => extensions}/Win32/System/Com/IDispatch.rs | 2 ++ 6 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 crates/libs/windows/src/extensions/Win32/System.rs create mode 100644 crates/libs/windows/src/extensions/Win32/System/Com.rs rename crates/libs/windows/src/{includes => extensions}/Win32/System/Com/IDispatch.rs (98%) diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index 491b3cd0ba..165cc2702d 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -37,7 +37,6 @@ pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { "Win32/Networking/WinSock/SOCKADDR_INET.rs", ]), "Windows.Win32.System.Rpc" => include_ext("Win32/System/Rpc/RPC_STATUS.rs"), - "Windows.Win32.System.Com" => include_ext("Win32/System/Com/IDispatch.rs"), _ => quote!(), } } diff --git a/crates/libs/windows/src/Windows/Win32/System/Com/mod.rs b/crates/libs/windows/src/Windows/Win32/System/Com/mod.rs index 14b61c13e4..706a484e0f 100644 --- a/crates/libs/windows/src/Windows/Win32/System/Com/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/System/Com/mod.rs @@ -7664,6 +7664,5 @@ pub type LPEXCEPFINO_DEFERRED_FILLIN = Option windows_core::HRESULT>; pub type LPFNGETCLASSOBJECT = Option windows_core::HRESULT>; pub type PFNCONTEXTCALL = Option windows_core::HRESULT>; -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/System/Com/IDispatch.rs")); #[cfg(feature = "implement")] core::include!("impl.rs"); diff --git a/crates/libs/windows/src/extensions/Win32.rs b/crates/libs/windows/src/extensions/Win32.rs index 9a6da9527b..c7d120b91d 100644 --- a/crates/libs/windows/src/extensions/Win32.rs +++ b/crates/libs/windows/src/extensions/Win32.rs @@ -1,2 +1,5 @@ #[cfg(feature = "Win32_Foundation")] pub mod Foundation; + +#[cfg(feature = "Win32_System")] +pub mod System; diff --git a/crates/libs/windows/src/extensions/Win32/System.rs b/crates/libs/windows/src/extensions/Win32/System.rs new file mode 100644 index 0000000000..326098352b --- /dev/null +++ b/crates/libs/windows/src/extensions/Win32/System.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "Win32_System_Com")] +pub mod Com; \ No newline at end of file diff --git a/crates/libs/windows/src/extensions/Win32/System/Com.rs b/crates/libs/windows/src/extensions/Win32/System/Com.rs new file mode 100644 index 0000000000..20ce5d02f4 --- /dev/null +++ b/crates/libs/windows/src/extensions/Win32/System/Com.rs @@ -0,0 +1 @@ +pub mod IDispatch; diff --git a/crates/libs/windows/src/includes/Win32/System/Com/IDispatch.rs b/crates/libs/windows/src/extensions/Win32/System/Com/IDispatch.rs similarity index 98% rename from crates/libs/windows/src/includes/Win32/System/Com/IDispatch.rs rename to crates/libs/windows/src/extensions/Win32/System/Com/IDispatch.rs index 84162b72fe..cf6a7070f6 100644 --- a/crates/libs/windows/src/includes/Win32/System/Com/IDispatch.rs +++ b/crates/libs/windows/src/extensions/Win32/System/Com/IDispatch.rs @@ -1,3 +1,5 @@ +use crate::Win32::System::Com::IDispatch; + impl From for windows_core::VARIANT { fn from(value: IDispatch) -> Self { unsafe { From 776f9851c0ffcac5f16ce93549a91dbdbeed75d3 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 13:37:17 -0700 Subject: [PATCH 06/12] Move RPC_STATUS --- crates/libs/bindgen/src/rust/extensions/mod.rs | 1 - crates/libs/windows/src/Windows/Win32/System/Rpc/mod.rs | 1 - crates/libs/windows/src/extensions/Win32/System.rs | 5 ++++- crates/libs/windows/src/extensions/Win32/System/Rpc.rs | 1 + .../{includes => extensions}/Win32/System/Rpc/RPC_STATUS.rs | 2 ++ 5 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 crates/libs/windows/src/extensions/Win32/System/Rpc.rs rename crates/libs/windows/src/{includes => extensions}/Win32/System/Rpc/RPC_STATUS.rs (94%) diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index 165cc2702d..d3ed0abb81 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -36,7 +36,6 @@ pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { "Win32/Networking/WinSock/SOCKADDR_IN6.rs", "Win32/Networking/WinSock/SOCKADDR_INET.rs", ]), - "Windows.Win32.System.Rpc" => include_ext("Win32/System/Rpc/RPC_STATUS.rs"), _ => quote!(), } } diff --git a/crates/libs/windows/src/Windows/Win32/System/Rpc/mod.rs b/crates/libs/windows/src/Windows/Win32/System/Rpc/mod.rs index f674fdb692..ce4d3b2434 100644 --- a/crates/libs/windows/src/Windows/Win32/System/Rpc/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/System/Rpc/mod.rs @@ -7088,4 +7088,3 @@ pub type USER_MARSHAL_SIZING_ROUTINE = Option *mut u8>; #[cfg(feature = "Win32_System_Com")] pub type XMIT_HELPER_ROUTINE = Option; -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/System/Rpc/RPC_STATUS.rs")); diff --git a/crates/libs/windows/src/extensions/Win32/System.rs b/crates/libs/windows/src/extensions/Win32/System.rs index 326098352b..7118c64d5e 100644 --- a/crates/libs/windows/src/extensions/Win32/System.rs +++ b/crates/libs/windows/src/extensions/Win32/System.rs @@ -1,2 +1,5 @@ #[cfg(feature = "Win32_System_Com")] -pub mod Com; \ No newline at end of file +pub mod Com; + +#[cfg(feature = "Win32_System_Rpc")] +mod Rpc; diff --git a/crates/libs/windows/src/extensions/Win32/System/Rpc.rs b/crates/libs/windows/src/extensions/Win32/System/Rpc.rs new file mode 100644 index 0000000000..b01ed132e6 --- /dev/null +++ b/crates/libs/windows/src/extensions/Win32/System/Rpc.rs @@ -0,0 +1 @@ +mod RPC_STATUS; diff --git a/crates/libs/windows/src/includes/Win32/System/Rpc/RPC_STATUS.rs b/crates/libs/windows/src/extensions/Win32/System/Rpc/RPC_STATUS.rs similarity index 94% rename from crates/libs/windows/src/includes/Win32/System/Rpc/RPC_STATUS.rs rename to crates/libs/windows/src/extensions/Win32/System/Rpc/RPC_STATUS.rs index fb79efb70d..f8a78d94c5 100644 --- a/crates/libs/windows/src/includes/Win32/System/Rpc/RPC_STATUS.rs +++ b/crates/libs/windows/src/extensions/Win32/System/Rpc/RPC_STATUS.rs @@ -1,3 +1,5 @@ +use crate::Win32::System::Rpc::RPC_STATUS; + impl RPC_STATUS { #[inline] pub const fn is_ok(self) -> bool { From 42996e0e906c1f6ab5ca98be7d2a14c193f5576c Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 13:59:47 -0700 Subject: [PATCH 07/12] move numerics --- crates/libs/bindgen/src/rust/extensions/mod.rs | 7 ------- crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs | 5 ----- crates/libs/windows/src/extensions/Foundation.rs | 4 ++-- crates/libs/windows/src/extensions/Foundation/Numerics.rs | 5 +++++ .../Foundation/Numerics/Matrix3x2.rs | 2 ++ .../Foundation/Numerics/Matrix4x4.rs | 2 ++ .../Foundation/Numerics/Vector2.rs | 2 ++ .../Foundation/Numerics/Vector3.rs | 2 ++ .../Foundation/Numerics/Vector4.rs | 2 ++ 9 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 crates/libs/windows/src/extensions/Foundation/Numerics.rs rename crates/libs/windows/src/{includes => extensions}/Foundation/Numerics/Matrix3x2.rs (98%) rename crates/libs/windows/src/{includes => extensions}/Foundation/Numerics/Matrix4x4.rs (99%) rename crates/libs/windows/src/{includes => extensions}/Foundation/Numerics/Vector2.rs (99%) rename crates/libs/windows/src/{includes => extensions}/Foundation/Numerics/Vector3.rs (99%) rename crates/libs/windows/src/{includes => extensions}/Foundation/Numerics/Vector4.rs (99%) diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index d3ed0abb81..3dfd989323 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -22,13 +22,6 @@ pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { } match namespace { - "Windows.Foundation.Numerics" => include_exts(&[ - "Foundation/Numerics/Matrix3x2.rs", - "Foundation/Numerics/Matrix4x4.rs", - "Foundation/Numerics/Vector2.rs", - "Foundation/Numerics/Vector3.rs", - "Foundation/Numerics/Vector4.rs", - ]), "Windows.Win32.Networking.WinSock" => include_exts(&[ "Win32/Networking/WinSock/IN_ADDR.rs", "Win32/Networking/WinSock/IN6_ADDR.rs", diff --git a/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs b/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs index e4ce26e57d..034ee20625 100644 --- a/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs @@ -157,8 +157,3 @@ impl Default for Vector4 { unsafe { core::mem::zeroed() } } } -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Matrix3x2.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Matrix4x4.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Vector2.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Vector3.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Numerics/Vector4.rs")); diff --git a/crates/libs/windows/src/extensions/Foundation.rs b/crates/libs/windows/src/extensions/Foundation.rs index 265a054e93..ea4bfd24ee 100644 --- a/crates/libs/windows/src/extensions/Foundation.rs +++ b/crates/libs/windows/src/extensions/Foundation.rs @@ -1,5 +1,5 @@ #[cfg(feature = "Foundation_Collections")] pub mod Collections; - +#[cfg(feature = "Foundation_Numerics")] +pub mod Numerics; pub mod TimeSpan; - diff --git a/crates/libs/windows/src/extensions/Foundation/Numerics.rs b/crates/libs/windows/src/extensions/Foundation/Numerics.rs new file mode 100644 index 0000000000..0f5dc4ba0b --- /dev/null +++ b/crates/libs/windows/src/extensions/Foundation/Numerics.rs @@ -0,0 +1,5 @@ +mod Matrix3x2; +mod Matrix4x4; +mod Vector2; +mod Vector3; +mod Vector4; diff --git a/crates/libs/windows/src/includes/Foundation/Numerics/Matrix3x2.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Matrix3x2.rs similarity index 98% rename from crates/libs/windows/src/includes/Foundation/Numerics/Matrix3x2.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Matrix3x2.rs index d5a132bd06..8d02cc822d 100644 --- a/crates/libs/windows/src/includes/Foundation/Numerics/Matrix3x2.rs +++ b/crates/libs/windows/src/extensions/Foundation/Numerics/Matrix3x2.rs @@ -1,3 +1,5 @@ +use crate::Foundation::Numerics::Matrix3x2; + impl Matrix3x2 { pub const fn identity() -> Self { Self { M11: 1.0, M12: 0.0, M21: 0.0, M22: 1.0, M31: 0.0, M32: 0.0 } diff --git a/crates/libs/windows/src/includes/Foundation/Numerics/Matrix4x4.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Matrix4x4.rs similarity index 99% rename from crates/libs/windows/src/includes/Foundation/Numerics/Matrix4x4.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Matrix4x4.rs index 132e8340d7..5048687314 100644 --- a/crates/libs/windows/src/includes/Foundation/Numerics/Matrix4x4.rs +++ b/crates/libs/windows/src/extensions/Foundation/Numerics/Matrix4x4.rs @@ -1,3 +1,5 @@ +use crate::Foundation::Numerics::Matrix4x4; + impl Matrix4x4 { pub const fn translation(x: f32, y: f32, z: f32) -> Self { Self { diff --git a/crates/libs/windows/src/includes/Foundation/Numerics/Vector2.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Vector2.rs similarity index 99% rename from crates/libs/windows/src/includes/Foundation/Numerics/Vector2.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Vector2.rs index 3926b0e77e..f2a1d365c4 100644 --- a/crates/libs/windows/src/includes/Foundation/Numerics/Vector2.rs +++ b/crates/libs/windows/src/extensions/Foundation/Numerics/Vector2.rs @@ -1,3 +1,5 @@ +use crate::Foundation::Numerics::Vector2; + impl Vector2 { pub fn new(X: f32, Y: f32) -> Self { Self { X, Y } diff --git a/crates/libs/windows/src/includes/Foundation/Numerics/Vector3.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Vector3.rs similarity index 99% rename from crates/libs/windows/src/includes/Foundation/Numerics/Vector3.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Vector3.rs index 3d9cba2933..a99ba3d9f4 100644 --- a/crates/libs/windows/src/includes/Foundation/Numerics/Vector3.rs +++ b/crates/libs/windows/src/extensions/Foundation/Numerics/Vector3.rs @@ -1,3 +1,5 @@ +use crate::Foundation::Numerics::Vector3; + impl Vector3 { pub fn new(X: f32, Y: f32, Z: f32) -> Self { Self { X, Y, Z } diff --git a/crates/libs/windows/src/includes/Foundation/Numerics/Vector4.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Vector4.rs similarity index 99% rename from crates/libs/windows/src/includes/Foundation/Numerics/Vector4.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Vector4.rs index e7c4ebf9c3..a0e5346b5b 100644 --- a/crates/libs/windows/src/includes/Foundation/Numerics/Vector4.rs +++ b/crates/libs/windows/src/extensions/Foundation/Numerics/Vector4.rs @@ -1,3 +1,5 @@ +use crate::Foundation::Numerics::Vector4; + impl Vector4 { pub fn new(X: f32, Y: f32, Z: f32, W: f32) -> Self { Self { X, Y, Z, W } From 6faaa9dd39f385d46fb72278aac82f0995545fc4 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 14:24:03 -0700 Subject: [PATCH 08/12] Move winsock extensions --- crates/libs/bindgen/src/rust/extensions/mod.rs | 16 +++++----------- .../src/Windows/Win32/Networking/WinSock/mod.rs | 5 ----- crates/libs/windows/src/extensions/Win32.rs | 7 ++++--- .../windows/src/extensions/Win32/Networking.rs | 2 ++ .../src/extensions/Win32/Networking/WinSock.rs | 5 +++++ .../Win32/Networking/WinSock/IN6_ADDR.rs | 2 ++ .../Win32/Networking/WinSock/IN_ADDR.rs | 2 ++ .../Win32/Networking/WinSock/SOCKADDR_IN.rs | 2 ++ .../Win32/Networking/WinSock/SOCKADDR_IN6.rs | 2 ++ .../Win32/Networking/WinSock/SOCKADDR_INET.rs | 2 ++ .../libs/windows/src/extensions/Win32/System.rs | 3 +-- 11 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 crates/libs/windows/src/extensions/Win32/Networking.rs create mode 100644 crates/libs/windows/src/extensions/Win32/Networking/WinSock.rs rename crates/libs/windows/src/{includes => extensions}/Win32/Networking/WinSock/IN6_ADDR.rs (86%) rename crates/libs/windows/src/{includes => extensions}/Win32/Networking/WinSock/IN_ADDR.rs (91%) rename crates/libs/windows/src/{includes => extensions}/Win32/Networking/WinSock/SOCKADDR_IN.rs (84%) rename crates/libs/windows/src/{includes => extensions}/Win32/Networking/WinSock/SOCKADDR_IN6.rs (88%) rename crates/libs/windows/src/{includes => extensions}/Win32/Networking/WinSock/SOCKADDR_INET.rs (91%) diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index 3dfd989323..6ad855b397 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -12,23 +12,17 @@ fn include_ext(relative_path: &str) -> TokenStream { } } -fn include_exts(relative_paths: &[&str]) -> TokenStream { - relative_paths.iter().map(|&p| include_ext(p)).collect() -} - +/// Generates extension code for a specific namespace +/// +/// This function allows us to inject code into modules generated by bindgen. +/// This feature is no longer needed but is preserved in case it is needed +/// again in the future. pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { if writer.sys { return quote!(); } match namespace { - "Windows.Win32.Networking.WinSock" => include_exts(&[ - "Win32/Networking/WinSock/IN_ADDR.rs", - "Win32/Networking/WinSock/IN6_ADDR.rs", - "Win32/Networking/WinSock/SOCKADDR_IN.rs", - "Win32/Networking/WinSock/SOCKADDR_IN6.rs", - "Win32/Networking/WinSock/SOCKADDR_INET.rs", - ]), _ => quote!(), } } diff --git a/crates/libs/windows/src/Windows/Win32/Networking/WinSock/mod.rs b/crates/libs/windows/src/Windows/Win32/Networking/WinSock/mod.rs index 3001c0db6d..82933fd984 100644 --- a/crates/libs/windows/src/Windows/Win32/Networking/WinSock/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/Networking/WinSock/mod.rs @@ -9395,8 +9395,3 @@ pub type LPWSPSOCKET = Option i32>; pub type LPWSPSTRINGTOADDRESS = Option i32>; -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/IN_ADDR.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/IN6_ADDR.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/SOCKADDR_IN.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/SOCKADDR_IN6.rs")); -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/Networking/WinSock/SOCKADDR_INET.rs")); diff --git a/crates/libs/windows/src/extensions/Win32.rs b/crates/libs/windows/src/extensions/Win32.rs index c7d120b91d..d5cdfbb870 100644 --- a/crates/libs/windows/src/extensions/Win32.rs +++ b/crates/libs/windows/src/extensions/Win32.rs @@ -1,5 +1,6 @@ #[cfg(feature = "Win32_Foundation")] -pub mod Foundation; - +mod Foundation; +#[cfg(feature = "Win32_Networking")] +mod Networking; #[cfg(feature = "Win32_System")] -pub mod System; +mod System; diff --git a/crates/libs/windows/src/extensions/Win32/Networking.rs b/crates/libs/windows/src/extensions/Win32/Networking.rs new file mode 100644 index 0000000000..ca8553e493 --- /dev/null +++ b/crates/libs/windows/src/extensions/Win32/Networking.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "Win32_Networking_WinSock")] +mod WinSock; diff --git a/crates/libs/windows/src/extensions/Win32/Networking/WinSock.rs b/crates/libs/windows/src/extensions/Win32/Networking/WinSock.rs new file mode 100644 index 0000000000..6e8be61482 --- /dev/null +++ b/crates/libs/windows/src/extensions/Win32/Networking/WinSock.rs @@ -0,0 +1,5 @@ +mod IN6_ADDR; +mod IN_ADDR; +mod SOCKADDR_IN; +mod SOCKADDR_IN6; +mod SOCKADDR_INET; diff --git a/crates/libs/windows/src/includes/Win32/Networking/WinSock/IN6_ADDR.rs b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/IN6_ADDR.rs similarity index 86% rename from crates/libs/windows/src/includes/Win32/Networking/WinSock/IN6_ADDR.rs rename to crates/libs/windows/src/extensions/Win32/Networking/WinSock/IN6_ADDR.rs index a0b37a987f..15a264c633 100644 --- a/crates/libs/windows/src/includes/Win32/Networking/WinSock/IN6_ADDR.rs +++ b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/IN6_ADDR.rs @@ -1,3 +1,5 @@ +use crate::Win32::Networking::WinSock::{IN6_ADDR, IN6_ADDR_0}; + impl From for IN6_ADDR { fn from(addr: std::net::Ipv6Addr) -> Self { Self { u: IN6_ADDR_0 { Byte: addr.octets() } } diff --git a/crates/libs/windows/src/includes/Win32/Networking/WinSock/IN_ADDR.rs b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/IN_ADDR.rs similarity index 91% rename from crates/libs/windows/src/includes/Win32/Networking/WinSock/IN_ADDR.rs rename to crates/libs/windows/src/extensions/Win32/Networking/WinSock/IN_ADDR.rs index 9e62b65198..b112e6dca9 100644 --- a/crates/libs/windows/src/includes/Win32/Networking/WinSock/IN_ADDR.rs +++ b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/IN_ADDR.rs @@ -1,3 +1,5 @@ +use crate::Win32::Networking::WinSock::{IN_ADDR, IN_ADDR_0}; + impl From for IN_ADDR { fn from(addr: std::net::Ipv4Addr) -> Self { // u32::from(addr) is in host byte order diff --git a/crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN.rs b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/SOCKADDR_IN.rs similarity index 84% rename from crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN.rs rename to crates/libs/windows/src/extensions/Win32/Networking/WinSock/SOCKADDR_IN.rs index bc305f44ee..7ef33f454d 100644 --- a/crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN.rs +++ b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/SOCKADDR_IN.rs @@ -1,3 +1,5 @@ +use crate::Win32::Networking::WinSock::{AF_INET, SOCKADDR_IN}; + impl From for SOCKADDR_IN { fn from(addr: std::net::SocketAddrV4) -> Self { // addr.port() is in host byte order diff --git a/crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN6.rs b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/SOCKADDR_IN6.rs similarity index 88% rename from crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN6.rs rename to crates/libs/windows/src/extensions/Win32/Networking/WinSock/SOCKADDR_IN6.rs index c494e3e1e2..331e61f5e5 100644 --- a/crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_IN6.rs +++ b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/SOCKADDR_IN6.rs @@ -1,3 +1,5 @@ +use crate::Win32::Networking::WinSock::{AF_INET6, SOCKADDR_IN6, SOCKADDR_IN6_0}; + impl From for SOCKADDR_IN6 { fn from(addr: std::net::SocketAddrV6) -> Self { // addr.port() and addr.flowinfo() are in host byte order diff --git a/crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_INET.rs b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/SOCKADDR_INET.rs similarity index 91% rename from crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_INET.rs rename to crates/libs/windows/src/extensions/Win32/Networking/WinSock/SOCKADDR_INET.rs index a86d289579..02460839e9 100644 --- a/crates/libs/windows/src/includes/Win32/Networking/WinSock/SOCKADDR_INET.rs +++ b/crates/libs/windows/src/extensions/Win32/Networking/WinSock/SOCKADDR_INET.rs @@ -1,3 +1,5 @@ +use crate::Win32::Networking::WinSock::SOCKADDR_INET; + impl From for SOCKADDR_INET { fn from(addr: std::net::SocketAddrV4) -> Self { SOCKADDR_INET { Ipv4: addr.into() } diff --git a/crates/libs/windows/src/extensions/Win32/System.rs b/crates/libs/windows/src/extensions/Win32/System.rs index 7118c64d5e..167a10c940 100644 --- a/crates/libs/windows/src/extensions/Win32/System.rs +++ b/crates/libs/windows/src/extensions/Win32/System.rs @@ -1,5 +1,4 @@ #[cfg(feature = "Win32_System_Com")] -pub mod Com; - +mod Com; #[cfg(feature = "Win32_System_Rpc")] mod Rpc; From 768b91ec2b5105b35ee3445f42a8b97ca7414b74 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 14:36:10 -0700 Subject: [PATCH 09/12] cleanup --- .../libs/bindgen/src/rust/extensions/mod.rs | 29 ++++++++++--------- .../Windows/Foundation/Collections/impl.rs | 1 - crates/libs/windows/src/extensions.rs | 15 ++++++++-- .../src/includes/Foundation/Collections.rs | 1 - crates/libs/windows/src/lib.rs | 3 +- 5 files changed, 30 insertions(+), 19 deletions(-) delete mode 100644 crates/libs/windows/src/includes/Foundation/Collections.rs diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index 6ad855b397..997aba0481 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -1,5 +1,12 @@ use super::*; +/// Helper function for `gen_mod` and `gen_impl`. +/// +/// This function generates an `include!(...)` that points into the +/// `src/includes` directory for the `windows` and `windows-sys` +/// crates. This is no longer needed, but is preserved in case it is +/// needed again in the future. +#[allow(dead_code)] fn include_ext(relative_path: &str) -> TokenStream { quote! { core::include!( @@ -17,19 +24,15 @@ fn include_ext(relative_path: &str) -> TokenStream { /// This function allows us to inject code into modules generated by bindgen. /// This feature is no longer needed but is preserved in case it is needed /// again in the future. -pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream { - if writer.sys { - return quote!(); - } - - match namespace { - _ => quote!(), - } +pub fn gen_mod(_writer: &Writer, _namespace: &str) -> TokenStream { + TokenStream::new() } -pub fn gen_impl(namespace: &str) -> TokenStream { - match namespace { - "Windows.Foundation.Collections" => include_ext("Foundation/Collections.rs"), - _ => quote!(), - } +/// Generates implementation extension code for a specific namespace +/// +/// This function allows us to inject code into modules generated by bindgen. +/// This feature is no longer needed but is preserved in case it is needed +/// again in the future. +pub fn gen_impl(_namespace: &str) -> TokenStream { + TokenStream::new() } diff --git a/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs b/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs index d1acb045d5..6f88940aa8 100644 --- a/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs +++ b/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs @@ -828,4 +828,3 @@ impl IVectorView_Vtbl { iid == & as windows_core::Interface>::IID } } -core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Foundation/Collections.rs")); diff --git a/crates/libs/windows/src/extensions.rs b/crates/libs/windows/src/extensions.rs index 7e8d8c5f34..caae20dca2 100644 --- a/crates/libs/windows/src/extensions.rs +++ b/crates/libs/windows/src/extensions.rs @@ -2,8 +2,19 @@ //! //! This module contains code that extends the functionality of the bindings generated by `bindgen`. //! It adds inherent impls, trait impls, etc. +//! +//! This module's visibility is `pub(crate)`, not `pub`, because the `extensions` module path is +//! not intended to be directly visible to user code. Associated functions defined within this +//! module tree use the visibility of the types they are associated with, and so the visibility +//! of this module tree does not constrain the visibility of the associated functions. Similarly, +//! trait impls _themselves_ do not have visibility; their visibility is defined by the types and +//! traits used in the trait impl definition. +//! +//! If it becomes necessary to re-export definitions (types, etc.) defined in this module tree, +//! then the right thing to do is to change the visibility (along those module paths) to `pub(crate)` +//! and then to use `pub` for the specific items that will be re-exported. #[cfg(feature = "Foundation")] -pub mod Foundation; +mod Foundation; #[cfg(feature = "Win32")] -pub mod Win32; +mod Win32; diff --git a/crates/libs/windows/src/includes/Foundation/Collections.rs b/crates/libs/windows/src/includes/Foundation/Collections.rs deleted file mode 100644 index 4d678edc12..0000000000 --- a/crates/libs/windows/src/includes/Foundation/Collections.rs +++ /dev/null @@ -1 +0,0 @@ -pub use crate::extensions::Foundation::Collections::*; diff --git a/crates/libs/windows/src/lib.rs b/crates/libs/windows/src/lib.rs index 7d50b11534..9cb770d101 100644 --- a/crates/libs/windows/src/lib.rs +++ b/crates/libs/windows/src/lib.rs @@ -17,7 +17,6 @@ extern crate self as windows; pub use windows_core as core; -#[doc(hidden)] -pub mod extensions; +mod extensions; include!("Windows/mod.rs"); From 8246bcf6d3df6d65b39a7287abaaf6a7741e47e0 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 14:36:34 -0700 Subject: [PATCH 10/12] rustfmt --- .../Foundation/Collections/Iterable.rs | 12 ++----- .../Foundation/Collections/MapView.rs | 35 ++++--------------- .../Foundation/Collections/VectorView.rs | 19 +++------- .../Win32/Foundation/VARIANT_BOOL.rs | 2 +- 4 files changed, 15 insertions(+), 53 deletions(-) diff --git a/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs b/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs index 8731fa22d3..205a2e48e9 100644 --- a/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs @@ -16,11 +16,7 @@ where { fn First(&self) -> windows_core::Result> { use windows_core::IUnknownImpl; - Ok(windows_core::ComObject::new(StockIterator { - owner: self.to_object(), - current: 0.into(), - }) - .into_interface()) + Ok(windows_core::ComObject::new(StockIterator { owner: self.to_object(), current: 0.into() }).into_interface()) } } @@ -62,8 +58,7 @@ where let current = self.current.load(std::sync::atomic::Ordering::Relaxed); if current < owner.values.len() { - self.current - .fetch_add(1, std::sync::atomic::Ordering::Relaxed); + self.current.fetch_add(1, std::sync::atomic::Ordering::Relaxed); } Ok(owner.values.len() > current + 1) @@ -76,8 +71,7 @@ where let actual = std::cmp::min(owner.values.len() - current, values.len()); let (values, _) = values.split_at_mut(actual); values.clone_from_slice(&owner.values[current..current + actual]); - self.current - .fetch_add(actual, std::sync::atomic::Ordering::Relaxed); + self.current.fetch_add(actual, std::sync::atomic::Ordering::Relaxed); Ok(actual as u32) } } diff --git a/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs b/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs index 7d709a84d9..c1ff6cdd35 100644 --- a/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs @@ -21,11 +21,7 @@ where fn First(&self) -> windows_core::Result>> { use windows_core::IUnknownImpl; - Ok(windows_core::ComObject::new(StockMapViewIterator:: { - _owner: self.to_object(), - current: std::sync::RwLock::new(self.map.iter()), - }) - .into_interface()) + Ok(windows_core::ComObject::new(StockMapViewIterator:: { _owner: self.to_object(), current: std::sync::RwLock::new(self.map.iter()) }).into_interface()) } } @@ -37,10 +33,7 @@ where V::Default: Clone, { fn Lookup(&self, key: &K::Default) -> windows_core::Result { - let value = self - .map - .get(key) - .ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?; + let value = self.map.get(key).ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?; V::from_default(value) } fn Size(&self) -> windows_core::Result { @@ -49,11 +42,7 @@ where fn HasKey(&self, key: &K::Default) -> windows_core::Result { Ok(self.map.contains_key(key)) } - fn Split( - &self, - first: &mut Option>, - second: &mut Option>, - ) -> windows_core::Result<()> { + fn Split(&self, first: &mut Option>, second: &mut Option>) -> windows_core::Result<()> { *first = None; *second = None; Ok(()) @@ -83,11 +72,7 @@ where let mut current = self.current.read().unwrap().clone().peekable(); if let Some((key, value)) = current.peek() { - Ok(windows_core::ComObject::new(StockKeyValuePair { - key: (*key).clone(), - value: (*value).clone(), - }) - .into_interface()) + Ok(windows_core::ComObject::new(StockKeyValuePair { key: (*key).clone(), value: (*value).clone() }).into_interface()) } else { Err(windows_core::Error::from(windows_core::imp::E_BOUNDS)) } @@ -112,13 +97,7 @@ where for pair in pairs { if let Some((key, value)) = current.next() { - *pair = Some( - windows_core::ComObject::new(StockKeyValuePair { - key: (*key).clone(), - value: (*value).clone(), - }) - .into_interface(), - ); + *pair = Some(windows_core::ComObject::new(StockKeyValuePair { key: (*key).clone(), value: (*value).clone() }).into_interface()); actual += 1; } else { break; @@ -164,9 +143,7 @@ where V::Default: Clone, { type Error = windows_core::Error; - fn try_from( - map: std::collections::BTreeMap, - ) -> windows_core::Result { + 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()) } diff --git a/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs b/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs index 53b13f97af..5021474323 100644 --- a/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs @@ -1,4 +1,4 @@ -use crate::Foundation::Collections::{IIterator, IIterator_Impl, IIterable, IIterable_Impl, IVectorView, IVectorView_Impl}; +use crate::Foundation::Collections::{IIterable, IIterable_Impl, IIterator, IIterator_Impl, IVectorView, IVectorView_Impl}; #[windows_core::implement(IVectorView, IIterable)] struct StockVectorView @@ -17,11 +17,7 @@ where fn First(&self) -> windows_core::Result> { use windows_core::IUnknownImpl; - Ok(windows_core::ComObject::new(StockVectorViewIterator { - owner: self.to_object(), - current: 0.into(), - }) - .into_interface()) + Ok(windows_core::ComObject::new(StockVectorViewIterator { owner: self.to_object(), current: 0.into() }).into_interface()) } } @@ -31,10 +27,7 @@ where T::Default: Clone + PartialEq, { fn GetAt(&self, index: u32) -> windows_core::Result { - let item = self - .values - .get(index as usize) - .ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?; + let item = self.values.get(index as usize).ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?; T::from_default(item) } fn Size(&self) -> windows_core::Result { @@ -95,8 +88,7 @@ where let current = self.current.load(std::sync::atomic::Ordering::Relaxed); if current < self.owner.values.len() { - self.current - .fetch_add(1, std::sync::atomic::Ordering::Relaxed); + self.current.fetch_add(1, std::sync::atomic::Ordering::Relaxed); } Ok(self.owner.values.len() > current + 1) @@ -108,8 +100,7 @@ where let actual = std::cmp::min(self.owner.values.len() - current, values.len()); let (values, _) = values.split_at_mut(actual); values.clone_from_slice(&self.owner.values[current..current + actual]); - self.current - .fetch_add(actual, std::sync::atomic::Ordering::Relaxed); + self.current.fetch_add(actual, std::sync::atomic::Ordering::Relaxed); Ok(actual as u32) } } diff --git a/crates/libs/windows/src/extensions/Win32/Foundation/VARIANT_BOOL.rs b/crates/libs/windows/src/extensions/Win32/Foundation/VARIANT_BOOL.rs index 628e022e2c..a212eb8e56 100644 --- a/crates/libs/windows/src/extensions/Win32/Foundation/VARIANT_BOOL.rs +++ b/crates/libs/windows/src/extensions/Win32/Foundation/VARIANT_BOOL.rs @@ -1,4 +1,4 @@ -use crate::Win32::Foundation::{VARIANT_BOOL, VARIANT_TRUE, VARIANT_FALSE}; +use crate::Win32::Foundation::{VARIANT_BOOL, VARIANT_FALSE, VARIANT_TRUE}; impl VARIANT_BOOL { #[inline] From fb4675f21eda3b0cf30284d70483fdc15fceead4 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 14:57:30 -0700 Subject: [PATCH 11/12] fix cfg for implement --- crates/libs/windows/src/extensions/Foundation/Collections.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/libs/windows/src/extensions/Foundation/Collections.rs b/crates/libs/windows/src/extensions/Foundation/Collections.rs index 4405f57e0f..771b249a74 100644 --- a/crates/libs/windows/src/extensions/Foundation/Collections.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections.rs @@ -1,3 +1,6 @@ +#[cfg(feature = "implement")] pub mod Iterable; +#[cfg(feature = "implement")] pub mod MapView; +#[cfg(feature = "implement")] pub mod VectorView; From 78a1ac4824370dad17a562ed462651c8ae6a4799 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Mon, 17 Jun 2024 15:39:34 -0700 Subject: [PATCH 12/12] revert extension change for WindowLong --- .../libs/bindgen/src/rust/extensions/mod.rs | 26 ++++++++----------- .../Win32/UI/WindowsAndMessaging/mod.rs | 1 + .../Win32/UI/WindowsAndMessaging/mod.rs | 1 + .../UI/WindowsAndMessaging/WindowLong.rs | 0 4 files changed, 13 insertions(+), 15 deletions(-) rename crates/libs/windows/src/{extensions => includes}/Win32/UI/WindowsAndMessaging/WindowLong.rs (100%) diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index 997aba0481..f5bdc92d87 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -2,10 +2,8 @@ use super::*; /// Helper function for `gen_mod` and `gen_impl`. /// -/// This function generates an `include!(...)` that points into the -/// `src/includes` directory for the `windows` and `windows-sys` -/// crates. This is no longer needed, but is preserved in case it is -/// needed again in the future. +/// This function generates an `include!(...)` that points into the `src/includes` directory for +/// the `windows` and `windows-sys` crates. This makes it easy to inject code into WinMD namespaces. #[allow(dead_code)] fn include_ext(relative_path: &str) -> TokenStream { quote! { @@ -20,19 +18,17 @@ fn include_ext(relative_path: &str) -> TokenStream { } /// Generates extension code for a specific namespace -/// -/// This function allows us to inject code into modules generated by bindgen. -/// This feature is no longer needed but is preserved in case it is needed -/// again in the future. -pub fn gen_mod(_writer: &Writer, _namespace: &str) -> TokenStream { - TokenStream::new() +pub fn gen_mod(_writer: &Writer, namespace: &str) -> TokenStream { + match namespace { + "Windows.Win32.UI.WindowsAndMessaging" => { + include_ext("Win32/UI/WindowsAndMessaging/WindowLong.rs") + } + + _ => quote!(), + } } -/// Generates implementation extension code for a specific namespace -/// -/// This function allows us to inject code into modules generated by bindgen. -/// This feature is no longer needed but is preserved in case it is needed -/// again in the future. +/// Generates extension code that is subject to the `implement` feature for a specific namespace pub fn gen_impl(_namespace: &str) -> TokenStream { TokenStream::new() } diff --git a/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs b/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs index 2e7b089f75..8271e63984 100644 --- a/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs +++ b/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs @@ -3752,3 +3752,4 @@ pub type SENDASYNCPROC = Option; pub type WNDENUMPROC = Option super::super::Foundation::BOOL>; pub type WNDPROC = Option super::super::Foundation::LRESULT>; +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/UI/WindowsAndMessaging/WindowLong.rs")); diff --git a/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs b/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs index c8900118b1..f56e256e79 100644 --- a/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs @@ -9426,3 +9426,4 @@ pub type SENDASYNCPROC = Option; pub type WNDENUMPROC = Option super::super::Foundation::BOOL>; pub type WNDPROC = Option super::super::Foundation::LRESULT>; +core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/UI/WindowsAndMessaging/WindowLong.rs")); diff --git a/crates/libs/windows/src/extensions/Win32/UI/WindowsAndMessaging/WindowLong.rs b/crates/libs/windows/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs similarity index 100% rename from crates/libs/windows/src/extensions/Win32/UI/WindowsAndMessaging/WindowLong.rs rename to crates/libs/windows/src/includes/Win32/UI/WindowsAndMessaging/WindowLong.rs