#proc-macro #cfg #panic #bodies #testing #unimplemented #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

#1875 in Rust patterns

Download history 526/week @ 2024-07-20 593/week @ 2024-07-27 500/week @ 2024-08-03 843/week @ 2024-08-10 826/week @ 2024-08-17 573/week @ 2024-08-24 688/week @ 2024-08-31 529/week @ 2024-09-07 648/week @ 2024-09-14 1115/week @ 2024-09-21 526/week @ 2024-09-28 757/week @ 2024-10-05 1248/week @ 2024-10-12 758/week @ 2024-10-19 753/week @ 2024-10-26 499/week @ 2024-11-02

3,496 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

~230–670KB
~16K SLoC