-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
578 changed files
with
84,677 additions
and
84,950 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,108 @@ | ||
use super::*; | ||
|
||
#[doc(hidden)] | ||
pub enum Param<T: Type<T>> { | ||
Owned(T), | ||
Borrowed(T::Abi), | ||
} | ||
|
||
impl<T: Type<T>> Param<T> { | ||
pub fn abi(&self) -> T::Abi { | ||
unsafe { | ||
match self { | ||
Self::Owned(item) => std::mem::transmute_copy(item), | ||
Self::Borrowed(borrowed) => std::mem::transmute_copy(borrowed), | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[doc(hidden)] | ||
pub trait CanInto<T>: Sized { | ||
const QUERY: bool = false; | ||
} | ||
|
||
impl<T> CanInto<T> for T where T: Clone {} | ||
|
||
#[doc(hidden)] | ||
pub trait IntoParam<T: TypeKind, C = <T as TypeKind>::TypeKind>: Sized | ||
/// 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>, | ||
{ | ||
unsafe fn into_param(self) -> Param<T>; | ||
#[doc(hidden)] | ||
unsafe fn param(self) -> ParamValue<T>; | ||
} | ||
|
||
impl<T> IntoParam<T> for Option<&T> | ||
impl<T> Param<T> for Option<&T> | ||
where | ||
T: Type<T>, | ||
{ | ||
unsafe fn into_param(self) -> Param<T> { | ||
Param::Borrowed(match self { | ||
unsafe fn param(self) -> ParamValue<T> { | ||
ParamValue::Borrowed(match self { | ||
Some(item) => std::mem::transmute_copy(item), | ||
None => std::mem::zeroed(), | ||
}) | ||
} | ||
} | ||
|
||
impl<T, U> IntoParam<T, ReferenceType> for &U | ||
impl<T, U> Param<T, InterfaceType> for &U | ||
where | ||
T: TypeKind<TypeKind = ReferenceType> + Clone, | ||
T: TypeKind<TypeKind = InterfaceType> + Clone, | ||
T: Interface, | ||
U: Interface, | ||
U: CanInto<T>, | ||
{ | ||
unsafe fn into_param(self) -> Param<T> { | ||
unsafe fn param(self) -> ParamValue<T> { | ||
if U::QUERY { | ||
self.cast().map_or(Param::Borrowed(std::mem::zeroed()), |ok| Param::Owned(ok)) | ||
self.cast().map_or(ParamValue::Borrowed(std::mem::zeroed()), |ok| ParamValue::Owned(ok)) | ||
} else { | ||
Param::Borrowed(std::mem::transmute_copy(self)) | ||
ParamValue::Borrowed(std::mem::transmute_copy(self)) | ||
} | ||
} | ||
} | ||
|
||
impl<T> IntoParam<T, ValueType> for &T | ||
impl<T> Param<T, CloneType> for &T | ||
where | ||
T: TypeKind<TypeKind = ValueType> + Clone, | ||
T: TypeKind<TypeKind = CloneType> + Clone, | ||
{ | ||
unsafe fn into_param(self) -> Param<T> { | ||
Param::Borrowed(std::mem::transmute_copy(self)) | ||
unsafe fn param(self) -> ParamValue<T> { | ||
ParamValue::Borrowed(std::mem::transmute_copy(self)) | ||
} | ||
} | ||
|
||
impl<T, U> IntoParam<T, CopyType> for U | ||
impl<T, U> Param<T, CopyType> for U | ||
where | ||
T: TypeKind<TypeKind = CopyType> + Clone, | ||
U: TypeKind<TypeKind = CopyType> + Clone, | ||
U: CanInto<T>, | ||
{ | ||
unsafe fn into_param(self) -> Param<T> { | ||
Param::Owned(std::mem::transmute_copy(&self)) | ||
unsafe fn param(self) -> ParamValue<T> { | ||
ParamValue::Owned(std::mem::transmute_copy(&self)) | ||
} | ||
} | ||
|
||
impl IntoParam<PCWSTR> for &BSTR { | ||
unsafe fn into_param(self) -> Param<PCWSTR> { | ||
Param::Owned(PCWSTR(self.as_ptr())) | ||
impl Param<PCWSTR> for &BSTR { | ||
unsafe fn param(self) -> ParamValue<PCWSTR> { | ||
ParamValue::Owned(PCWSTR(self.as_ptr())) | ||
} | ||
} | ||
|
||
impl IntoParam<PCWSTR> for &HSTRING { | ||
unsafe fn into_param(self) -> Param<PCWSTR> { | ||
Param::Owned(PCWSTR(self.as_ptr())) | ||
impl Param<PCWSTR> for &HSTRING { | ||
unsafe fn param(self) -> ParamValue<PCWSTR> { | ||
ParamValue::Owned(PCWSTR(self.as_ptr())) | ||
} | ||
} | ||
|
||
impl IntoParam<PCWSTR> for PWSTR { | ||
unsafe fn into_param(self) -> Param<PCWSTR> { | ||
Param::Owned(PCWSTR(self.0)) | ||
impl Param<PCWSTR> for PWSTR { | ||
unsafe fn param(self) -> ParamValue<PCWSTR> { | ||
ParamValue::Owned(PCWSTR(self.0)) | ||
} | ||
} | ||
|
||
impl IntoParam<PCSTR> for PSTR { | ||
unsafe fn into_param(self) -> Param<PCSTR> { | ||
Param::Owned(PCSTR(self.0)) | ||
impl Param<PCSTR> for PSTR { | ||
unsafe fn param(self) -> ParamValue<PCSTR> { | ||
ParamValue::Owned(PCSTR(self.0)) | ||
} | ||
} | ||
|
||
#[doc(hidden)] | ||
pub enum ParamValue<T: Type<T>> { | ||
Owned(T), | ||
Borrowed(T::Abi), | ||
} | ||
|
||
impl<T: Type<T>> ParamValue<T> { | ||
pub fn abi(&self) -> T::Abi { | ||
unsafe { | ||
match self { | ||
Self::Owned(item) => std::mem::transmute_copy(item), | ||
Self::Borrowed(borrowed) => std::mem::transmute_copy(borrowed), | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[doc(hidden)] | ||
pub trait CanInto<T>: Sized { | ||
const QUERY: bool = false; | ||
} | ||
|
||
impl<T> CanInto<T> for T where T: Clone {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.