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

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

#1171 in Rust patterns

Download history 605/week @ 2024-09-13 1144/week @ 2024-09-20 616/week @ 2024-09-27 537/week @ 2024-10-04 1228/week @ 2024-10-11 865/week @ 2024-10-18 758/week @ 2024-10-25 657/week @ 2024-11-01 621/week @ 2024-11-08 885/week @ 2024-11-15 875/week @ 2024-11-22 645/week @ 2024-11-29 608/week @ 2024-12-06 536/week @ 2024-12-13 563/week @ 2024-12-20 558/week @ 2024-12-27

2,382 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

~215–650KB
~16K SLoC