9 releases
| 0.2.8 | Sep 24, 2025 |
|---|---|
| 0.2.7 | Jun 18, 2024 |
| 0.2.6 | Feb 12, 2023 |
| 0.2.5 | Jan 27, 2023 |
| 0.2.0 | Jun 26, 2021 |
#521 in Rust patterns
Used in 4 crates
(3 directly)
15KB
190 lines
cfg-iif
A macro for defining #[cfg] if-else functions.
The macro provided by this crate.
Unlike cfg_if,
cfg_iif can be used as a function, and can be used in a function.
Features
- minimum support rustc 1.60.0 (7737e0b5c 2022-04-04)
Example
Example 1: #[cfg()]
a_iifis "unix" when a os is Unix at compile time:
use cfg_iif::cfg_iif;
let a_iif = cfg_iif!(#[cfg(target_family = "unix")] { "unix" } else { "not unix" });
a_iifis "abc" when a feature is "has_abc" at compile time:
use cfg_iif::cfg_iif;
let a_iif = cfg_iif!(#[cfg(feature = "has_abc")] { "abc" } else { "not abc" });
a_iifis "abc" when a feature is "has_abc" at compile time:
use cfg_iif::cfg_iif;
let mut a_iif = "";
cfg_iif!(
#[cfg(feature = "has_abc")]
{
a_iif = "abc";
}
);
Example 2: a short hand for a firendly cargo fmt
a_iifis "abc" when a feature is "has_abc" at compile time:
use cfg_iif::cfg_iif;
let a_iif = cfg_iif!(feature = "has_abc" { "abc" } else { "not abc" });
a_iifis "abc" when a feature is "has_abc" at compile time:
use cfg_iif::cfg_iif;
let mut a_iif = "";
cfg_iif!(feature = "has_abc" {
a_iif = "abc";
});
Changelogs
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.