#cfg #macro #cfg-iif

cfg-iif

A macro for defining #[cfg] if-else functions

8 releases

0.2.7 Jun 18, 2024
0.2.6 Feb 12, 2023
0.2.5 Jan 27, 2023
0.2.3 Jun 13, 2022
0.2.0 Jun 26, 2021

#219 in Rust patterns

Download history 38/week @ 2025-01-18 45/week @ 2025-01-25 117/week @ 2025-02-01 176/week @ 2025-02-08 101/week @ 2025-02-15 96/week @ 2025-02-22 1260/week @ 2025-03-01 9757/week @ 2025-03-08 7222/week @ 2025-03-15 5107/week @ 2025-03-22 13491/week @ 2025-03-29 19641/week @ 2025-04-05 20292/week @ 2025-04-12 15534/week @ 2025-04-19 10812/week @ 2025-04-26 10960/week @ 2025-05-03

60,886 downloads per month
Used in 4 crates (3 directly)

MIT/Apache

12KB
189 lines

cfg-iif

crate Docs Rust Version Apache2/MIT licensed Test ubu Test mac Test win

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.56.1 (59eed8a2a 2021-11-01)

Example

Example 1: #[cfg()]

  • a_iif is "unix" when a os is Unix at compile time:
use cfg_iif::cfg_iif;
let a_iif = cfg_iif!(#[cfg(Unix)] { "unix" } else { "not unix" });
  • a_iif is "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_iif is "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_iif is "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_iif is "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";
});

Documentation

Changelogs

This crate's changelog here.

License

This project is licensed under either of

at your option.

No runtime deps

Features