chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
#[cfg(feature = "Foundation_Collections")]
pub mod Collections;
#[cfg(feature = "Foundation_Numerics")]
pub mod Numerics;
pub mod TimeSpan;

View File

@@ -0,0 +1,6 @@
#[cfg(feature = "implement")]
pub mod Iterable;
#[cfg(feature = "implement")]
pub mod MapView;
#[cfg(feature = "implement")]
pub mod VectorView;

View File

@@ -0,0 +1,89 @@
use crate::Foundation::Collections::{IIterable, IIterable_Impl, IIterator, IIterator_Impl};
#[windows_core::implement(IIterable<T>)]
struct StockIterable<T>
where
T: windows_core::RuntimeType + 'static,
T::Default: Clone,
{
values: Vec<T::Default>,
}
impl<T> IIterable_Impl<T> for StockIterable_Impl<T>
where
T: windows_core::RuntimeType,
T::Default: Clone,
{
fn First(&self) -> windows_core::Result<IIterator<T>> {
use windows_core::IUnknownImpl;
Ok(windows_core::ComObject::new(StockIterator { owner: self.to_object(), current: 0.into() }).into_interface())
}
}
#[windows_core::implement(IIterator<T>)]
struct StockIterator<T>
where
T: windows_core::RuntimeType + 'static,
T::Default: Clone,
{
owner: windows_core::ComObject<StockIterable<T>>,
current: std::sync::atomic::AtomicUsize,
}
impl<T> IIterator_Impl<T> for StockIterator_Impl<T>
where
T: windows_core::RuntimeType,
T::Default: Clone,
{
fn Current(&self) -> windows_core::Result<T> {
let owner: &StockIterable<T> = &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<bool> {
let owner: &StockIterable<T> = &self.owner;
let current = self.current.load(std::sync::atomic::Ordering::Relaxed);
Ok(owner.values.len() > current)
}
fn MoveNext(&self) -> windows_core::Result<bool> {
let owner: &StockIterable<T> = &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<u32> {
let owner: &StockIterable<T> = &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<T> TryFrom<Vec<T::Default>> for IIterable<T>
where
T: windows_core::RuntimeType,
T::Default: Clone,
{
type Error = windows_core::Error;
fn try_from(values: Vec<T::Default>) -> windows_core::Result<Self> {
// TODO: should provide a fallible try_into or more explicit allocator
Ok(windows_core::ComObject::new(StockIterable { values }).into_interface())
}
}

View File

@@ -0,0 +1,150 @@
use crate::Foundation::Collections::{IIterable, IIterable_Impl, IIterator, IIterator_Impl, IKeyValuePair, IKeyValuePair_Impl, IMapView, IMapView_Impl};
#[windows_core::implement(IMapView<K, V>, IIterable<IKeyValuePair<K, V>>)]
struct StockMapView<K, V>
where
K: windows_core::RuntimeType + 'static,
V: windows_core::RuntimeType + 'static,
K::Default: Clone + Ord,
V::Default: Clone,
{
map: std::collections::BTreeMap<K::Default, V::Default>,
}
impl<K, V> IIterable_Impl<IKeyValuePair<K, V>> for StockMapView_Impl<K, V>
where
K: windows_core::RuntimeType,
V: windows_core::RuntimeType,
K::Default: Clone + Ord,
V::Default: Clone,
{
fn First(&self) -> windows_core::Result<IIterator<IKeyValuePair<K, V>>> {
use windows_core::IUnknownImpl;
Ok(windows_core::ComObject::new(StockMapViewIterator::<K, V> { _owner: self.to_object(), current: std::sync::RwLock::new(self.map.iter()) }).into_interface())
}
}
impl<K, V> IMapView_Impl<K, V> for StockMapView_Impl<K, V>
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<V> {
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<u32> {
Ok(self.map.len().try_into()?)
}
fn HasKey(&self, key: &K::Default) -> windows_core::Result<bool> {
Ok(self.map.contains_key(key))
}
fn Split(&self, first: &mut Option<IMapView<K, V>>, second: &mut Option<IMapView<K, V>>) -> windows_core::Result<()> {
*first = None;
*second = None;
Ok(())
}
}
#[windows_core::implement(IIterator<IKeyValuePair<K, V>>)]
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<StockMapView<K, V>>,
current: std::sync::RwLock<std::collections::btree_map::Iter<'a, K::Default, V::Default>>,
}
impl<'a, K, V> IIterator_Impl<IKeyValuePair<K, V>> 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<IKeyValuePair<K, V>> {
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<bool> {
let mut current = self.current.read().unwrap().clone().peekable();
Ok(current.peek().is_some())
}
fn MoveNext(&self) -> windows_core::Result<bool> {
let mut current = self.current.write().unwrap();
current.next();
Ok(current.clone().peekable().peek().is_some())
}
fn GetMany(&self, pairs: &mut [Option<IKeyValuePair<K, V>>]) -> windows_core::Result<u32> {
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<K, V>)]
struct StockKeyValuePair<K, V>
where
K: windows_core::RuntimeType + 'static,
V: windows_core::RuntimeType + 'static,
K::Default: Clone,
V::Default: Clone,
{
key: K::Default,
value: V::Default,
}
impl<K, V> IKeyValuePair_Impl<K, V> for StockKeyValuePair_Impl<K, V>
where
K: windows_core::RuntimeType,
V: windows_core::RuntimeType,
K::Default: Clone,
V::Default: Clone,
{
fn Key(&self) -> windows_core::Result<K> {
K::from_default(&self.key)
}
fn Value(&self) -> windows_core::Result<V> {
V::from_default(&self.value)
}
}
impl<K, V> TryFrom<std::collections::BTreeMap<K::Default, V::Default>> for IMapView<K, V>
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<K::Default, V::Default>) -> windows_core::Result<Self> {
// TODO: should provide a fallible try_into or more explicit allocator
Ok(StockMapView { map }.into())
}
}

View File

@@ -0,0 +1,118 @@
use crate::Foundation::Collections::{IIterable, IIterable_Impl, IIterator, IIterator_Impl, IVectorView, IVectorView_Impl};
#[windows_core::implement(IVectorView<T>, IIterable<T>)]
struct StockVectorView<T>
where
T: windows_core::RuntimeType + 'static,
T::Default: Clone + PartialEq,
{
values: Vec<T::Default>,
}
impl<T> IIterable_Impl<T> for StockVectorView_Impl<T>
where
T: windows_core::RuntimeType,
T::Default: Clone + PartialEq,
{
fn First(&self) -> windows_core::Result<IIterator<T>> {
use windows_core::IUnknownImpl;
Ok(windows_core::ComObject::new(StockVectorViewIterator { owner: self.to_object(), current: 0.into() }).into_interface())
}
}
impl<T> IVectorView_Impl<T> for StockVectorView_Impl<T>
where
T: windows_core::RuntimeType,
T::Default: Clone + PartialEq,
{
fn GetAt(&self, index: u32) -> windows_core::Result<T> {
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<u32> {
Ok(self.values.len().try_into()?)
}
fn IndexOf(&self, value: &T::Default, result: &mut u32) -> windows_core::Result<bool> {
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<u32> {
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<T>)]
struct StockVectorViewIterator<T>
where
T: windows_core::RuntimeType + 'static,
T::Default: Clone + PartialEq,
{
owner: windows_core::ComObject<StockVectorView<T>>,
current: std::sync::atomic::AtomicUsize,
}
impl<T> IIterator_Impl<T> for StockVectorViewIterator_Impl<T>
where
T: windows_core::RuntimeType,
T::Default: Clone + PartialEq,
{
fn Current(&self) -> windows_core::Result<T> {
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<bool> {
let current = self.current.load(std::sync::atomic::Ordering::Relaxed);
Ok(self.owner.values.len() > current)
}
fn MoveNext(&self) -> windows_core::Result<bool> {
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<u32> {
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<T> TryFrom<Vec<T::Default>> for IVectorView<T>
where
T: windows_core::RuntimeType,
T::Default: Clone + PartialEq,
{
type Error = windows_core::Error;
fn try_from(values: Vec<T::Default>) -> windows_core::Result<Self> {
// TODO: should provide a fallible try_into or more explicit allocator
Ok(windows_core::ComObject::new(StockVectorView { values }).into_interface())
}
}

View File

@@ -0,0 +1,5 @@
mod Matrix3x2;
mod Matrix4x4;
mod Vector2;
mod Vector3;
mod Vector4;

View File

@@ -0,0 +1,141 @@
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 }
}
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<Matrix3x2> 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<Matrix3x2> 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<Matrix3x2> 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<Matrix3x2> 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<Matrix3x2> 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<Matrix3x2> 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<f32> for Matrix3x2 {
type Output = Matrix3x2;
fn mul(self, rhs: f32) -> Matrix3x2 {
self.impl_mul_f32(rhs)
}
}
impl core::ops::Mul<f32> for &Matrix3x2 {
type Output = Matrix3x2;
fn mul(self, rhs: f32) -> Matrix3x2 {
self.impl_mul_f32(rhs)
}
}

View File

@@ -0,0 +1,237 @@
use crate::Foundation::Numerics::Matrix4x4;
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<Matrix4x4> 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<Matrix4x4> 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<Matrix4x4> 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<Matrix4x4> 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<Matrix4x4> 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<Matrix4x4> 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<f32> for Matrix4x4 {
type Output = Matrix4x4;
fn mul(self, rhs: f32) -> Matrix4x4 {
self.impl_mul_f32(rhs)
}
}
impl core::ops::Mul<f32> for &Matrix4x4 {
type Output = Matrix4x4;
fn mul(self, rhs: f32) -> Matrix4x4 {
self.impl_mul_f32(rhs)
}
}

View File

@@ -0,0 +1,177 @@
use crate::Foundation::Numerics::Vector2;
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<Vector2> 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<Vector2> 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<Vector2> 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<Vector2> 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<Vector2> 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<Vector2> 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<f32> for Vector2 {
type Output = Vector2;
fn div(self, rhs: f32) -> Vector2 {
self.impl_div_f32(rhs)
}
}
impl core::ops::Div<f32> for &Vector2 {
type Output = Vector2;
fn div(self, rhs: f32) -> Vector2 {
self.impl_div_f32(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<&Vector2> 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<&Vector2> for &Vector2 {
type Output = Vector2;
fn mul(self, rhs: &Vector2) -> Vector2 {
self.impl_mul(rhs)
}
}
impl core::ops::Mul<f32> for Vector2 {
type Output = Vector2;
fn mul(self, rhs: f32) -> Vector2 {
self.impl_mul_f32(rhs)
}
}
impl core::ops::Mul<f32> for &Vector2 {
type Output = Vector2;
fn mul(self, rhs: f32) -> Vector2 {
self.impl_mul_f32(rhs)
}
}

View File

@@ -0,0 +1,180 @@
use crate::Foundation::Numerics::Vector3;
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<Vector3> 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<Vector3> 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<Vector3> 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<Vector3> 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<Vector3> 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<Vector3> 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<f32> for Vector3 {
type Output = Vector3;
fn div(self, rhs: f32) -> Vector3 {
self.impl_div_f32(rhs)
}
}
impl core::ops::Div<f32> for &Vector3 {
type Output = Vector3;
fn div(self, rhs: f32) -> Vector3 {
self.impl_div_f32(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<&Vector3> 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<&Vector3> for &Vector3 {
type Output = Vector3;
fn mul(self, rhs: &Vector3) -> Vector3 {
self.impl_mul(rhs)
}
}
impl core::ops::Mul<f32> for Vector3 {
type Output = Vector3;
fn mul(self, rhs: f32) -> Vector3 {
self.impl_mul_f32(rhs)
}
}
impl core::ops::Mul<f32> for &Vector3 {
type Output = Vector3;
fn mul(self, rhs: f32) -> Vector3 {
self.impl_mul_f32(rhs)
}
}

View File

@@ -0,0 +1,183 @@
use crate::Foundation::Numerics::Vector4;
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<Vector4> 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<Vector4> 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<Vector4> 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<Vector4> 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<Vector4> 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<Vector4> 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<f32> for Vector4 {
type Output = Vector4;
fn div(self, rhs: f32) -> Vector4 {
self.impl_div_f32(rhs)
}
}
impl core::ops::Div<f32> for &Vector4 {
type Output = Vector4;
fn div(self, rhs: f32) -> Vector4 {
self.impl_div_f32(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<&Vector4> 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<&Vector4> for &Vector4 {
type Output = Vector4;
fn mul(self, rhs: &Vector4) -> Vector4 {
self.impl_mul(rhs)
}
}
impl core::ops::Mul<f32> for Vector4 {
type Output = Vector4;
fn mul(self, rhs: f32) -> Vector4 {
self.impl_mul_f32(rhs)
}
}
impl core::ops::Mul<f32> for &Vector4 {
type Output = Vector4;
fn mul(self, rhs: f32) -> Vector4 {
self.impl_mul_f32(rhs)
}
}

View File

@@ -0,0 +1,12 @@
use crate::Foundation::TimeSpan;
impl From<core::time::Duration> for TimeSpan {
fn from(value: core::time::Duration) -> Self {
Self { Duration: (value.as_nanos() / 100) as i64 }
}
}
impl From<TimeSpan> for core::time::Duration {
fn from(value: TimeSpan) -> Self {
core::time::Duration::from_nanos((value.Duration * 100) as u64)
}
}

View File

@@ -0,0 +1,6 @@
#[cfg(feature = "Win32_Foundation")]
mod Foundation;
#[cfg(feature = "Win32_Networking")]
mod Networking;
#[cfg(feature = "Win32_System")]
mod System;

View File

@@ -0,0 +1,5 @@
pub mod BOOL;
pub mod BOOLEAN;
pub mod NTSTATUS;
pub mod VARIANT_BOOL;
pub mod WIN32_ERROR;

View File

@@ -0,0 +1,75 @@
use crate::Win32::Foundation::BOOL;
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<BOOL> 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<bool> 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<bool> for BOOL {
fn eq(&self, other: &bool) -> bool {
self.as_bool() == *other
}
}
impl PartialEq<BOOL> 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<BOOL> for bool {
unsafe fn param(self) -> windows_core::ParamValue<BOOL> {
windows_core::ParamValue::Owned(self.into())
}
}

View File

@@ -0,0 +1,75 @@
use crate::Win32::Foundation::BOOLEAN;
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<BOOLEAN> 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<bool> 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<bool> for BOOLEAN {
fn eq(&self, other: &bool) -> bool {
self.as_bool() == *other
}
}
impl PartialEq<BOOLEAN> 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<BOOLEAN> for bool {
unsafe fn param(self) -> windows_core::ParamValue<BOOLEAN> {
windows_core::ParamValue::Owned(self.into())
}
}

View File

@@ -0,0 +1,34 @@
use crate::Win32::Foundation::NTSTATUS;
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<NTSTATUS> for windows_core::HRESULT {
fn from(value: NTSTATUS) -> Self {
value.to_hresult()
}
}
impl From<NTSTATUS> for windows_core::Error {
fn from(value: NTSTATUS) -> Self {
value.to_hresult().into()
}
}

View File

@@ -0,0 +1,70 @@
use crate::Win32::Foundation::{VARIANT_BOOL, VARIANT_FALSE, VARIANT_TRUE};
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<VARIANT_BOOL> 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<bool> 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<bool> for VARIANT_BOOL {
fn eq(&self, other: &bool) -> bool {
self.as_bool() == *other
}
}
impl PartialEq<VARIANT_BOOL> 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
}
}
}

View File

@@ -0,0 +1,43 @@
use crate::Win32::Foundation::WIN32_ERROR;
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<Self> {
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<WIN32_ERROR> for windows_core::HRESULT {
fn from(value: WIN32_ERROR) -> Self {
value.to_hresult()
}
}
impl From<WIN32_ERROR> for windows_core::Error {
fn from(value: WIN32_ERROR) -> Self {
value.to_hresult().into()
}
}

View File

@@ -0,0 +1,2 @@
#[cfg(feature = "Win32_Networking_WinSock")]
mod WinSock;

View File

@@ -0,0 +1,5 @@
mod IN6_ADDR;
mod IN_ADDR;
mod SOCKADDR_IN;
mod SOCKADDR_IN6;
mod SOCKADDR_INET;

View File

@@ -0,0 +1,13 @@
use crate::Win32::Networking::WinSock::{IN6_ADDR, IN6_ADDR_0};
impl From<std::net::Ipv6Addr> for IN6_ADDR {
fn from(addr: std::net::Ipv6Addr) -> Self {
Self { u: IN6_ADDR_0 { Byte: addr.octets() } }
}
}
impl From<IN6_ADDR> 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 })
}
}

View File

@@ -0,0 +1,17 @@
use crate::Win32::Networking::WinSock::{IN_ADDR, IN_ADDR_0};
impl From<std::net::Ipv4Addr> 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<IN_ADDR> 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 }))
}
}

View File

@@ -0,0 +1,9 @@
use crate::Win32::Networking::WinSock::{AF_INET, SOCKADDR_IN};
impl From<std::net::SocketAddrV4> 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() }
}
}

View File

@@ -0,0 +1,17 @@
use crate::Win32::Networking::WinSock::{AF_INET6, SOCKADDR_IN6, SOCKADDR_IN6_0};
impl From<std::net::SocketAddrV6> 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()
}
}
}

View File

@@ -0,0 +1,20 @@
use crate::Win32::Networking::WinSock::SOCKADDR_INET;
impl From<std::net::SocketAddrV4> for SOCKADDR_INET {
fn from(addr: std::net::SocketAddrV4) -> Self {
SOCKADDR_INET { Ipv4: addr.into() }
}
}
impl From<std::net::SocketAddrV6> for SOCKADDR_INET {
fn from(addr: std::net::SocketAddrV6) -> Self {
SOCKADDR_INET { Ipv6: addr.into() }
}
}
impl From<std::net::SocketAddr> 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(),
}
}
}

View File

@@ -0,0 +1,4 @@
#[cfg(feature = "Win32_System_Com")]
mod Com;
#[cfg(feature = "Win32_System_Rpc")]
mod Rpc;

View File

@@ -0,0 +1 @@
pub mod IDispatch;

View File

@@ -0,0 +1,55 @@
use crate::Win32::System::Com::IDispatch;
impl From<IDispatch> 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<IDispatch> 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<Self> {
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<Self> {
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))
}
}
}
}

View File

@@ -0,0 +1 @@
mod RPC_STATUS;

View File

@@ -0,0 +1,34 @@
use crate::Win32::System::Rpc::RPC_STATUS;
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<RPC_STATUS> for windows_core::HRESULT {
fn from(value: RPC_STATUS) -> Self {
value.to_hresult()
}
}
impl From<RPC_STATUS> for windows_core::Error {
fn from(value: RPC_STATUS) -> Self {
value.to_hresult().into()
}
}