Crates.io | cfg-elif |
lib.rs | cfg-elif |
version | 0.6.5 |
created_at | 2025-01-22 23:52:32.227962+00 |
updated_at | 2025-09-20 04:33:22.577447+00 |
description | Formatter-friendly conditional compilation at item and expression positions |
homepage | |
repository | https://github.com/raviqqe/cfg-elif |
max_upload_size | |
id | 1527254 |
size | 19,230 |
The rustfmt
-friendly conditional compilation like cfg-if
.
rustfmt
friendlyuse 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
);