#position #cfg #friendly

cfg-elif

Formatter-friendly conditional compilation at item and expression positions

4 releases

Uses new Rust 2024

0.6.3 Feb 28, 2025
0.6.2 Feb 28, 2025
0.6.1 Jan 23, 2025
0.6.0 Jan 22, 2025

#359 in Rust patterns

Download history 624/week @ 2025-01-18 300/week @ 2025-01-25 396/week @ 2025-02-01 515/week @ 2025-02-08 365/week @ 2025-02-15 324/week @ 2025-02-22 780/week @ 2025-03-01 383/week @ 2025-03-08 528/week @ 2025-03-15 541/week @ 2025-03-22

2,360 downloads per month
Used in 29 crates (4 directly)

Custom license

14KB
218 lines

cfg-elif

GitHub Action Crate License

The rustfmt-friendly conditional compilation like cfg-if.

Features

  • Conditional compilation at both expression and item positions
  • rustfmt friendly

Examples

use cfg_elif::{expr, item};

item::cfg!(if (feature == "foo") {
    type Foo = usize;
} else if (target_pointer_width != "64") {
    type Foo = isize;
} else if ((target_family == "unix") && (feature == "bar")) {
    type Foo = i32;
} else if ((feature == "baz") || (target_os == "freebsd")) {
    type Foo = i64;
} else if (!(panic == "unwind")) {
    type Foo = i128;
} else {
    type Foo = f64;
});

assert_eq!(3.14 as Foo, 3.14);

assert_eq!(
    expr::cfg!(if (feature == "foo") {
        0
    } else if (target_pointer_width != "64") {
        1
    } else if ((target_family == "unix") && (feature == "bar")) {
        2
    } else if ((feature == "baz") || (target_os == "freebsd")) {
        3
    } else if (!(panic == "unwind")) {
        4
    } else {
        42
    }),
    42
);

License

The Unlicense

No runtime deps

Features