cfg-iif

Crates.iocfg-iif
lib.rscfg-iif
version0.2.7
sourcesrc
created_at2021-06-26 01:32:59.701374
updated_at2024-06-18 23:57:51.227787
descriptionA macro for defining `#[cfg]` `if-else` functions.
homepage
repositoryhttps://github.com/aki-akaguma/cfg-iif
max_upload_size
id415047
size31,962
(aki-akaguma)

documentation

README

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.

Commit count: 28

cargo fmt