1 /// A macro for defining #[cfg] if-else statements.
3 /// This is similar to the `if/elif` C preprocessor macro by allowing definition
4 /// of a cascade of `#[cfg]` cases, emitting the implementation which matches
7 /// This allows you to conveniently provide a long list #[cfg]'d blocks of code
8 /// without having to rewrite each clause multiple times.
11 if #[cfg($($meta:meta),*)] { $($it:item)* }
17 $
( ( ($
($meta
),*) ($
($it
)*) ), )*
23 macro_rules
! __cfg_if_items
{
24 (($
($not
:meta
,)*) ; ) => {}
;
25 (($
($not
:meta
,)*) ; ( ($
($m
:meta
),*) ($
($it
:item
)*) ), $
($rest
:tt
)*) => {
26 __cfg_if_apply
! { cfg(all($($m,)* not(any($($not),*)))), $($it)* }
27 __cfg_if_items
! { ($($not,)* $($m,)*) ; $($rest)* }
31 macro_rules
! __cfg_if_apply
{
32 ($m
:meta
, $
($it
:item
)*) => {
38 ($
(pub struct $i
:ident { $($field:tt)* }
)*) => ($
(
41 pub struct $i { $($field)* }
43 impl ::dox
::Copy
for $i {}
44 impl ::dox
::Clone
for $i
{
45 fn clone(&self) -> $i { *self }
51 ($
(pub fn $i
:ident($
($arg
:ident
: $argty
:ty
),*) -> $ret
:ty
{
56 pub unsafe extern fn $
i($
($arg
: $argty
),*) -> $ret
{
62 pub unsafe extern fn $
i($
($arg
: $argty
),*) -> $ret
{
76 use std
::option
::Option
as Option2
;
77 fn works1() -> Option2
<u32> { Some(1) }
79 fn works1() -> Option
<u32> { None }
85 fn works2() -> bool { false }
86 } else if #[cfg(test)] {
87 fn works2() -> bool { true }
89 fn works2() -> bool { false }
95 fn works3() -> bool { false }
97 fn works3() -> bool { true }
103 assert
!(works1().is_some());