musli_zerocopy/swiss/raw/
macros.rs

1// See the cfg-if crate.
2macro_rules! cfg_if {
3    // match if/else chains with a final `else`
4    ($(
5        if #[cfg($($meta:meta),*)] { $($it:item)* }
6    ) else * else {
7        $($it2:item)*
8    }) => {
9        cfg_if! {
10            @__items
11            () ;
12            $( ( ($($meta),*) ($($it)*) ), )*
13            ( () ($($it2)*) ),
14        }
15    };
16
17    // match if/else chains lacking a final `else`
18    (
19        if #[cfg($($i_met:meta),*)] { $($i_it:item)* }
20        $(
21            else if #[cfg($($e_met:meta),*)] { $($e_it:item)* }
22        )*
23    ) => {
24        cfg_if! {
25            @__items
26            () ;
27            ( ($($i_met),*) ($($i_it)*) ),
28            $( ( ($($e_met),*) ($($e_it)*) ), )*
29            ( () () ),
30        }
31    };
32
33    // Internal and recursive macro to emit all the items
34    //
35    // Collects all the negated cfgs in a list at the beginning and after the
36    // semicolon is all the remaining items
37    (@__items ($($not:meta,)*) ; ) => {};
38    (@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => {
39        // Emit all items within one block, applying an appropriate #[cfg]. The
40        // #[cfg] will require all `$m` matchers specified and must also negate
41        // all previous matchers.
42        cfg_if! { @__apply cfg(all($($m,)* not(any($($not),*)))), $($it)* }
43
44        // Recurse to emit all other items in `$rest`, and when we do so add all
45        // our `$m` matchers to the list of `$not` matchers as future emissions
46        // will have to negate everything we just matched as well.
47        cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* }
48    };
49
50    // Internal macro to Apply a cfg attribute to a list of items
51    (@__apply $m:meta, $($it:item)*) => {
52        $(#[$m] $it)*
53    };
54}