#cfg #macro #proc-macro

macro cfg-or-panic

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

3 unstable releases

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

#718 in Rust patterns

Download history 4689/week @ 2024-02-04 977/week @ 2024-02-11 3768/week @ 2024-02-18 5355/week @ 2024-02-25 4929/week @ 2024-03-03 3898/week @ 2024-03-10 4739/week @ 2024-03-17 4565/week @ 2024-03-24 3991/week @ 2024-03-31 4587/week @ 2024-04-07 4412/week @ 2024-04-14 3672/week @ 2024-04-21 1904/week @ 2024-04-28 3461/week @ 2024-05-05 2900/week @ 2024-05-12 2712/week @ 2024-05-19

11,110 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

~335–800KB
~19K SLoC