/
bool32.rs
125 lines (105 loc) · 3.1 KB
/
bool32.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use super::*;
pub fn gen() -> TokenStream {
quote! {
#[repr(transparent)]
pub struct BOOL(pub i32);
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 ::core::default::Default for BOOL {
fn default() -> Self {
Self(0)
}
}
impl ::core::clone::Clone for BOOL {
fn clone(&self) -> Self {
*self
}
}
impl ::core::marker::Copy for BOOL {}
impl ::core::cmp::PartialEq for BOOL {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for BOOL {}
impl ::core::fmt::Debug for BOOL {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("BOOL").field(&self.0).finish()
}
}
impl ::core::convert::From<BOOL> for bool {
fn from(value: BOOL) -> Self {
value.as_bool()
}
}
impl ::core::convert::From<&BOOL> for bool {
fn from(value: &BOOL) -> Self {
value.as_bool()
}
}
impl ::core::convert::From<bool> for BOOL {
fn from(value: bool) -> Self {
if value {
BOOL(1)
} else {
BOOL(0)
}
}
}
impl ::core::convert::From<&bool> for BOOL {
fn from(value: &bool) -> Self {
(*value).into()
}
}
impl ::core::cmp::PartialEq<bool> for BOOL {
fn eq(&self, other: &bool) -> bool {
self.as_bool() == *other
}
}
impl ::core::cmp::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() {
BOOL(0)
} else {
BOOL(1)
}
}
}
unsafe impl ::windows::core::Abi for BOOL {
type Abi = Self;
}
impl<'a> ::windows::core::IntoParam<'a, BOOL> for bool {
fn into_param(self) -> ::windows::core::Param<'a, BOOL> {
::windows::core::Param::Owned(self.into())
}
}
}
}