macro_rules! cfg_table {
() => { ... };
(_ => $expr:expr,) => { ... };
([$cfg:meta] => $expr:expr, $($tail:tt)*) => { ... };
(32 => $expr:expr, $($tail:tt)*) => { ... };
(64 => $expr:expr, $($tail:tt)*) => { ... };
("32" => $expr:expr, $($tail:tt)*) => { ... };
("64" => $expr:expr, $($tail:tt)*) => { ... };
(macos => $expr:expr, $($tail:tt)*) => { ... };
(linux => $expr:expr, $($tail:tt)*) => { ... };
(windows => $expr:expr, $($tail:tt)*) => { ... };
(macos32 => $expr:expr, $($tail:tt)*) => { ... };
(macos64 => $expr:expr, $($tail:tt)*) => { ... };
(linux32 => $expr:expr, $($tail:tt)*) => { ... };
(linux64 => $expr:expr, $($tail:tt)*) => { ... };
(win32 => $expr:expr, $($tail:tt)*) => { ... };
(win64 => $expr:expr, $($tail:tt)*) => { ... };
}Expand description
A simple macro that expands to different values across compilation targets.
Note, that you must have a leading , in the macro invocation.
§Panics
This macro will panic at runtime if no matching value is found.
§Example
let var = cfg_table! {
[all(target_os = "freebsd", target_pointer_width = "64", feature = "my-feature")] => 1337, // custom
// common platforms
win32 => 32,
win64 => 64,
linux32 => 32,
linux64 => 64,
macos32 => 32,
macos64 => 64,
// pointer widths
32 => 1985,
"32" => 1985,
64 => 2003,
"64" => 2003,
_ => 123, // default value if nothing matches, this must be at the bottom
};
cfg_table! {
win32 => {
println!("You're on Windows 32-bit!");
},
win64 => {
println!("You're on Windows 64-bit!");
},
_ => {
panic!("What the heck is a \"Linux\"?");
},
};