File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 19
19
/// }
20
20
/// }
21
21
/// ```
22
+ ///
23
+ /// Example with casting, due to a mistake in libc. In this example, the
24
+ /// various flags have different types, so we cast the broken ones to the right
25
+ /// type.
26
+ ///
27
+ /// ```
28
+ /// libc_bitflags!{
29
+ /// pub flags SaFlags: libc::c_ulong {
30
+ /// SA_NOCLDSTOP as libc::c_ulong,
31
+ /// SA_NOCLDWAIT,
32
+ /// SA_NODEFER as libc::c_ulong,
33
+ /// SA_ONSTACK,
34
+ /// SA_RESETHAND as libc::c_ulong,
35
+ /// SA_RESTART as libc::c_ulong,
36
+ /// SA_SIGINFO,
37
+ /// }
38
+ /// }
39
+ /// ```
22
40
macro_rules! libc_bitflags {
23
41
// (non-pub) Exit rule.
24
42
( @call_bitflags
@@ -130,6 +148,22 @@ macro_rules! libc_bitflags {
130
148
}
131
149
} ;
132
150
151
+ // Munch last ident and cast it to the given type.
152
+ ( @accumulate_flags
153
+ $prefix: tt,
154
+ [ $( $flags: tt) * ] ;
155
+ $flag: ident as $ty: ty
156
+ ) => {
157
+ libc_bitflags! {
158
+ @accumulate_flags
159
+ $prefix,
160
+ [
161
+ $( $flags) *
162
+ const $flag = libc:: $flag as $ty;
163
+ ] ;
164
+ }
165
+ } ;
166
+
133
167
// Munch an ident; covers terminating comma case.
134
168
( @accumulate_flags
135
169
$prefix: tt,
@@ -147,6 +181,24 @@ macro_rules! libc_bitflags {
147
181
}
148
182
} ;
149
183
184
+ // Munch an ident and cast it to the given type; covers terminating comma
185
+ // case.
186
+ ( @accumulate_flags
187
+ $prefix: tt,
188
+ [ $( $flags: tt) * ] ;
189
+ $flag: ident as $ty: ty, $( $tail: tt) *
190
+ ) => {
191
+ libc_bitflags! {
192
+ @accumulate_flags
193
+ $prefix,
194
+ [
195
+ $( $flags) *
196
+ const $flag = libc:: $flag as $ty;
197
+ ] ;
198
+ $( $tail) *
199
+ }
200
+ } ;
201
+
150
202
// (non-pub) Entry rule.
151
203
(
152
204
$( #[ $attr: meta] ) *
You can’t perform that action at this time.
0 commit comments