diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
| commit | 8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch) | |
| tree | 22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/windows-core/src/out_param.rs | |
| parent | 4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff) | |
chore: add vendor directory
Diffstat (limited to 'vendor/windows-core/src/out_param.rs')
| -rw-r--r-- | vendor/windows-core/src/out_param.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/windows-core/src/out_param.rs b/vendor/windows-core/src/out_param.rs new file mode 100644 index 00000000..828746c1 --- /dev/null +++ b/vendor/windows-core/src/out_param.rs @@ -0,0 +1,63 @@ +use super::*; +use core::mem::{take, transmute_copy, zeroed}; + +/// Provides automatic parameter conversion in cases where the Windows API expects implicit conversion support. +/// +/// This is a mutable version of [Param] meant to support out parameters. +/// There is no need to implement this trait. Blanket implementations are provided for all applicable Windows types. +pub trait OutParam<T: TypeKind, C = <T as TypeKind>::TypeKind>: Sized +where + T: Type<T>, +{ + #[doc(hidden)] + unsafe fn borrow_mut(&self) -> OutRef<'_, T>; +} + +impl<T> OutParam<T, CloneType> for &mut T +where + T: TypeKind<TypeKind = CloneType> + Clone + Default, +{ + unsafe fn borrow_mut(&self) -> OutRef<'_, T> { + unsafe { + let this: &mut T = transmute_copy(self); + take(this); + transmute_copy(self) + } + } +} + +impl<T> OutParam<T, CopyType> for &mut T +where + T: TypeKind<TypeKind = CopyType> + Clone + Default, +{ + unsafe fn borrow_mut(&self) -> OutRef<'_, T> { + unsafe { transmute_copy(self) } + } +} + +impl<T> OutParam<T, InterfaceType> for &mut Option<T> +where + T: TypeKind<TypeKind = InterfaceType> + Clone, +{ + unsafe fn borrow_mut(&self) -> OutRef<'_, T> { + unsafe { + let this: &mut Option<T> = transmute_copy(self); + take(this); + transmute_copy(self) + } + } +} + +impl<T> OutParam<T> for Option<&mut T> +where + T: Type<T>, +{ + unsafe fn borrow_mut(&self) -> OutRef<'_, T> { + unsafe { + match self { + Some(this) => transmute_copy(this), + None => zeroed(), + } + } + } +} |
