summaryrefslogtreecommitdiff
path: root/vendor/windows-core/src/param.rs
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
committermo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
commit8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch)
tree22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/windows-core/src/param.rs
parent4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff)
chore: add vendor directory
Diffstat (limited to 'vendor/windows-core/src/param.rs')
-rw-r--r--vendor/windows-core/src/param.rs76
1 files changed, 76 insertions, 0 deletions
diff --git a/vendor/windows-core/src/param.rs b/vendor/windows-core/src/param.rs
new file mode 100644
index 00000000..5ebf3add
--- /dev/null
+++ b/vendor/windows-core/src/param.rs
@@ -0,0 +1,76 @@
+use super::*;
+use core::mem::transmute_copy;
+use core::mem::zeroed;
+
+/// Provides automatic parameter conversion in cases where the Windows API expects implicit conversion support.
+///
+/// There is no need to implement this trait. Blanket implementations are provided for all applicable Windows types.
+pub trait Param<T: TypeKind, C = <T as TypeKind>::TypeKind>: Sized
+where
+ T: Type<T>,
+{
+ #[doc(hidden)]
+ unsafe fn param(self) -> ParamValue<T>;
+}
+
+impl<T> Param<T> for Option<&T>
+where
+ T: Type<T>,
+{
+ unsafe fn param(self) -> ParamValue<T> {
+ unsafe {
+ ParamValue::Borrowed(match self {
+ Some(item) => transmute_copy(item),
+ None => zeroed(),
+ })
+ }
+ }
+}
+
+impl<T> Param<T> for InterfaceRef<'_, T>
+where
+ T: Type<T>,
+{
+ unsafe fn param(self) -> ParamValue<T> {
+ unsafe { ParamValue::Borrowed(transmute_copy(&self)) }
+ }
+}
+
+impl<T, U> Param<T, InterfaceType> for &U
+where
+ T: TypeKind<TypeKind = InterfaceType> + Clone,
+ T: Interface,
+ U: Interface,
+ U: imp::CanInto<T>,
+{
+ unsafe fn param(self) -> ParamValue<T> {
+ unsafe {
+ if U::QUERY {
+ self.cast()
+ .map_or(ParamValue::Borrowed(zeroed()), |ok| ParamValue::Owned(ok))
+ } else {
+ ParamValue::Borrowed(transmute_copy(self))
+ }
+ }
+ }
+}
+
+impl<T> Param<T, CloneType> for &T
+where
+ T: TypeKind<TypeKind = CloneType> + Clone,
+{
+ unsafe fn param(self) -> ParamValue<T> {
+ unsafe { ParamValue::Borrowed(transmute_copy(self)) }
+ }
+}
+
+impl<T, U> Param<T, CopyType> for U
+where
+ T: TypeKind<TypeKind = CopyType> + Clone,
+ U: TypeKind<TypeKind = CopyType> + Clone,
+ U: imp::CanInto<T>,
+{
+ unsafe fn param(self) -> ParamValue<T> {
+ unsafe { ParamValue::Owned(transmute_copy(&self)) }
+ }
+}