[−][src]Macro cfg_match::cfg_match
cfg_match!
provides a more ergonomic approach to chaining conditionals,
like the similar cfg-if crate. In
addition to items, cfg_match!
can also be used for expressions (though a
block will require parenthesis wrapping like => ({ ... })
).
Compile-time conditionals
The macro stops at the first matching branch, just like a traditional match:
cfg_match! { feature = "foo" => { fn bar() { println!("have foo"); } } _ => fn bar() { println!("no foo :("); } }
Alternatively, the above can be written as:
cfg_match! { #[cfg(feature = "foo")] /// Does a thing because of foo. fn bar() { println!("have foo"); } #[cfg(_)] fn bar() { println!("no foo :("); } }