#proc-macro #cfg #panic #bodies #condition #macro #unimplemented

macro cfg-or-panic

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

3 unstable releases

0.2.1 May 21, 2024
0.2.0 Sep 19, 2023
0.1.1 Aug 30, 2023
0.1.0 Aug 30, 2023

#964 in Rust patterns

Download history 831/week @ 2024-06-13 637/week @ 2024-06-20 836/week @ 2024-06-27 887/week @ 2024-07-04 840/week @ 2024-07-11 552/week @ 2024-07-18 571/week @ 2024-07-25 540/week @ 2024-08-01 749/week @ 2024-08-08 821/week @ 2024-08-15 661/week @ 2024-08-22 663/week @ 2024-08-29 524/week @ 2024-09-05 620/week @ 2024-09-12 1066/week @ 2024-09-19 721/week @ 2024-09-26

3,080 downloads per month

Apache-2.0

8KB
131 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

~275–730KB
~17K SLoC