pub macro cfg_select($($tt:tt)*) {
...
}
cfg_select #115585)
Selects code at compile-time based on cfg predicates.
This macro evaluates, at compile-time, a series of cfg predicates, selects the first that is true, and emits the code guarded by that predicate. The code guarded by other predicates is not emitted.
An optional trailing _ wildcard can be used to specify a fallback. If none of the predicates are true, a compile_error is emitted.
#![feature(cfg_select)]
cfg_select! {
unix => {
fn foo() { /* unix specific functionality */ }
}
target_pointer_width = "32" => {
fn foo() { /* non-unix, 32-bit functionality */ }
}
_ => {
fn foo() { /* fallback implementation */ }
}
}The cfg_select! macro can also be used in expression position, with or without braces on the right-hand side:
#![feature(cfg_select)]
let _some_string = cfg_select! {
unix => "With great power comes great electricity bills",
_ => { "Behind every successful diet is an unwatched pizza" }
};
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/macro.cfg_select.html