#cfg #macro #proc-macro

macro cfg-or-panic

Replace function bodies with unimplemented!() when condition is not met

2 unstable releases

0.2.0 Sep 19, 2023
0.1.1 Aug 30, 2023
0.1.0 Aug 30, 2023

#1065 in Rust patterns

Download history 5383/week @ 2024-01-05 5229/week @ 2024-01-12 5964/week @ 2024-01-19 5842/week @ 2024-01-26 5633/week @ 2024-02-02 1030/week @ 2024-02-09 2629/week @ 2024-02-16 5903/week @ 2024-02-23 4426/week @ 2024-03-01 4119/week @ 2024-03-08 4941/week @ 2024-03-15 4818/week @ 2024-03-22 4053/week @ 2024-03-29 4386/week @ 2024-04-05 4217/week @ 2024-04-12 3206/week @ 2024-04-19

17,260 downloads per month

Apache-2.0

8KB
137 lines

#[cfg_or_panic(..)]

Keep the function body under #[cfg(..)], or replace it with unimplemented!() under #[cfg(not(..))].

Example

use cfg_or_panic::cfg_or_panic;

#[cfg_or_panic(feature = "foo")]
fn foo() -> i32 {
    42
}

#[test]
#[cfg_attr(not(feature = "foo"), should_panic)]
fn test() {
    assert_eq!(foo(), 42);
}

Dependencies

~0.4–0.8MB
~20K SLoC