diff --git a/crates/libs/bindgen/src/rust/extensions/mod.rs b/crates/libs/bindgen/src/rust/extensions/mod.rs index 3a42b9b452..f5bdc92d87 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod.rs +++ b/crates/libs/bindgen/src/rust/extensions/mod.rs @@ -1,55 +1,34 @@ use super::*; -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(); - } - - if writer.sys { - return "".into(); +/// 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 makes it easy to inject code into WinMD namespaces. +#[allow(dead_code)] +fn include_ext(relative_path: &str) -> TokenStream { + quote! { + core::include!( + core::concat!( + core::env!("CARGO_MANIFEST_DIR"), + "/src/includes/", + #relative_path + ) + ); } +} +/// Generates extension code for a specific namespace +pub fn gen_mod(_writer: &Writer, namespace: &str) -> TokenStream { 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.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"), - ), - _ => "", - } - .into() +/// 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 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..6f88940aa8 100644 --- a/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs +++ b/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs @@ -828,354 +828,3 @@ 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()) - } -} diff --git a/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs b/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs index a2746505e1..034ee20625 100644 --- a/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/Numerics/mod.rs @@ -157,911 +157,3 @@ 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) - } -} diff --git a/crates/libs/windows/src/Windows/Foundation/mod.rs b/crates/libs/windows/src/Windows/Foundation/mod.rs index f05aafbeff..1ba0d86d51 100644 --- a/crates/libs/windows/src/Windows/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/mod.rs @@ -3216,15 +3216,5 @@ 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) - } -} #[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 3cdd6f0f90..23ecce8104 100644 --- a/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs @@ -11088,290 +11088,3 @@ 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() - } -} 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..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,69 +9395,3 @@ 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(), - } - } -} 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..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,58 +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>; -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)) - } - } - } -} #[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..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,35 +7088,3 @@ 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() - } -} 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 918c9cef80..53d1cb553d 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..caae20dca2 --- /dev/null +++ b/crates/libs/windows/src/extensions.rs @@ -0,0 +1,20 @@ +//! 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. +//! +//! 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")] +mod Foundation; +#[cfg(feature = "Win32")] +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..ea4bfd24ee --- /dev/null +++ b/crates/libs/windows/src/extensions/Foundation.rs @@ -0,0 +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/Collections.rs b/crates/libs/windows/src/extensions/Foundation/Collections.rs new file mode 100644 index 0000000000..771b249a74 --- /dev/null +++ b/crates/libs/windows/src/extensions/Foundation/Collections.rs @@ -0,0 +1,6 @@ +#[cfg(feature = "implement")] +pub mod Iterable; +#[cfg(feature = "implement")] +pub mod MapView; +#[cfg(feature = "implement")] +pub mod VectorView; diff --git a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/Iterable.rs b/crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs similarity index 87% rename from crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/Iterable.rs rename to crates/libs/windows/src/extensions/Foundation/Collections/Iterable.rs index 3a1854cfa4..205a2e48e9 100644 --- a/crates/libs/bindgen/src/rust/extensions/impl/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 @@ -14,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()) } } @@ -60,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) @@ -74,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/bindgen/src/rust/extensions/impl/Foundation/Collections/MapView.rs b/crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs similarity index 79% rename from crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/MapView.rs rename to crates/libs/windows/src/extensions/Foundation/Collections/MapView.rs index eca599138d..c1ff6cdd35 100644 --- a/crates/libs/bindgen/src/rust/extensions/impl/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 @@ -19,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()) } } @@ -35,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 { @@ -47,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(()) @@ -81,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)) } @@ -110,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; @@ -162,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/bindgen/src/rust/extensions/impl/Foundation/Collections/VectorView.rs b/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs similarity index 88% rename from crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/VectorView.rs rename to crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs index 94de4e5d05..5021474323 100644 --- a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/VectorView.rs +++ b/crates/libs/windows/src/extensions/Foundation/Collections/VectorView.rs @@ -1,3 +1,5 @@ +use crate::Foundation::Collections::{IIterable, IIterable_Impl, IIterator, IIterator_Impl, IVectorView, IVectorView_Impl}; + #[windows_core::implement(IVectorView, IIterable)] struct StockVectorView where @@ -15,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()) } } @@ -29,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 { @@ -93,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) @@ -106,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/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/bindgen/src/rust/extensions/mod/Foundation/Numerics/Matrix3x2.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Matrix3x2.rs similarity index 98% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Matrix3x2.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Matrix3x2.rs index d5a132bd06..8d02cc822d 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/Foundation/Numerics/Matrix4x4.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Matrix4x4.rs similarity index 99% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Matrix4x4.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Matrix4x4.rs index 132e8340d7..5048687314 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector2.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Vector2.rs similarity index 99% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector2.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Vector2.rs index 3926b0e77e..f2a1d365c4 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector3.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Vector3.rs similarity index 99% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector3.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Vector3.rs index 3d9cba2933..a99ba3d9f4 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector4.rs b/crates/libs/windows/src/extensions/Foundation/Numerics/Vector4.rs similarity index 99% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/Numerics/Vector4.rs rename to crates/libs/windows/src/extensions/Foundation/Numerics/Vector4.rs index e7c4ebf9c3..a0e5346b5b 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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 } diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Foundation/TimeSpan.rs b/crates/libs/windows/src/extensions/Foundation/TimeSpan.rs similarity index 90% rename from crates/libs/bindgen/src/rust/extensions/mod/Foundation/TimeSpan.rs rename to crates/libs/windows/src/extensions/Foundation/TimeSpan.rs index 510fd18a53..6fb2fd69b5 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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..d5cdfbb870 --- /dev/null +++ b/crates/libs/windows/src/extensions/Win32.rs @@ -0,0 +1,6 @@ +#[cfg(feature = "Win32_Foundation")] +mod Foundation; +#[cfg(feature = "Win32_Networking")] +mod Networking; +#[cfg(feature = "Win32_System")] +mod System; 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/bindgen/src/rust/extensions/mod/Win32/Foundation/BOOL.rs b/crates/libs/windows/src/extensions/Win32/Foundation/BOOL.rs similarity index 97% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/BOOL.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/BOOL.rs index 60cfd39fca..42bc5d9f00 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/Win32/Foundation/BOOLEAN.rs b/crates/libs/windows/src/extensions/Win32/Foundation/BOOLEAN.rs similarity index 97% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/BOOLEAN.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/BOOLEAN.rs index 7f6a9cc20d..43dd9dffed 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/Win32/Foundation/NTSTATUS.rs b/crates/libs/windows/src/extensions/Win32/Foundation/NTSTATUS.rs similarity index 94% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/NTSTATUS.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/NTSTATUS.rs index 2ec25a8cef..2d40cf001f 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/Win32/Foundation/VARIANT_BOOL.rs b/crates/libs/windows/src/extensions/Win32/Foundation/VARIANT_BOOL.rs similarity index 95% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/VARIANT_BOOL.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/VARIANT_BOOL.rs index 2505030176..a212eb8e56 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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_FALSE, VARIANT_TRUE}; + impl VARIANT_BOOL { #[inline] pub fn as_bool(self) -> bool { diff --git a/crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/WIN32_ERROR.rs b/crates/libs/windows/src/extensions/Win32/Foundation/WIN32_ERROR.rs similarity index 95% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/Foundation/WIN32_ERROR.rs rename to crates/libs/windows/src/extensions/Win32/Foundation/WIN32_ERROR.rs index 3b0579b354..91ee28549a 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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 new file mode 100644 index 0000000000..167a10c940 --- /dev/null +++ b/crates/libs/windows/src/extensions/Win32/System.rs @@ -0,0 +1,4 @@ +#[cfg(feature = "Win32_System_Com")] +mod Com; +#[cfg(feature = "Win32_System_Rpc")] +mod Rpc; 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/bindgen/src/rust/extensions/mod/Win32/System/Com/IDispatch.rs b/crates/libs/windows/src/extensions/Win32/System/Com/IDispatch.rs similarity index 98% rename from crates/libs/bindgen/src/rust/extensions/mod/Win32/System/Com/IDispatch.rs rename to crates/libs/windows/src/extensions/Win32/System/Com/IDispatch.rs index 84162b72fe..cf6a7070f6 100644 --- a/crates/libs/bindgen/src/rust/extensions/mod/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 { 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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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/bindgen/src/rust/extensions/mod/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 { 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");