| 1 |
#![cfg_attr(rustfmt, rustfmt_skip)] // https://github.com/rust-lang-nursery/rustfmt/issues/2754 |
| 2 |
|
| 3 |
// Vendored from the static-cond crate as macro re-exports are not available in stable Rust. |
| 4 |
// https://github.com/durka/static-cond/blob/36aa2dd/src/lib.rs |
| 5 |
// |
| 6 |
// Code is dual licensed under MIT/Apache-2.0 |
| 7 |
// Copyright (c) 2016 Alex Burka |
| 8 |
#[macro_export] |
| 9 |
#[doc(hidden)] |
| 10 |
macro_rules! static_cond { |
| 11 |
// private rule to define and call the local macro |
| 12 |
(@go $lhs:tt $rhs:tt $arm1:tt $arm2:tt) => { |
| 13 |
// note that the inner macro has no captures (it can't, because there's no way to escape `$`) |
| 14 |
macro_rules! __static_cond { |
| 15 |
($lhs $lhs) => $arm1; |
| 16 |
($lhs $rhs) => $arm2 |
| 17 |
} |
| 18 |
|
| 19 |
__static_cond!($lhs $rhs); |
| 20 |
}; |
| 21 |
|
| 22 |
// no else condition provided: fall through with empty else |
| 23 |
(if $lhs:tt == $rhs:tt $then:tt) => { |
| 24 |
$crate::static_cond!(if $lhs == $rhs $then else { }); |
| 25 |
}; |
| 26 |
(if $lhs:tt != $rhs:tt $then:tt) => { |
| 27 |
$crate::static_cond!(if $lhs != $rhs $then else { }); |
| 28 |
}; |
| 29 |
|
| 30 |
// we evaluate a conditional by generating a new macro (in an inner scope, so name shadowing is |
| 31 |
// not a big concern) and calling it |
| 32 |
(if $lhs:tt == $rhs:tt $then:tt else $els:tt) => { |
| 33 |
$crate::static_cond!(@go $lhs $rhs $then $els); |
| 34 |
}; |
| 35 |
(if $lhs:tt != $rhs:tt $then:tt else $els:tt) => { |
| 36 |
$crate::static_cond!(@go $lhs $rhs $els $then); |
| 37 |
}; |
| 38 |
} |