#proc-macro #cfg #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

#38 in #cfg

Download history 1966/week @ 2025-11-02 1595/week @ 2025-11-09 1079/week @ 2025-11-16 4327/week @ 2025-11-23 1961/week @ 2025-11-30 1441/week @ 2025-12-07 1333/week @ 2025-12-14 828/week @ 2025-12-21 500/week @ 2025-12-28 1255/week @ 2026-01-04 1026/week @ 2026-01-11 1362/week @ 2026-01-18 1140/week @ 2026-01-25 1001/week @ 2026-02-01 1247/week @ 2026-02-08 1410/week @ 2026-02-15

4,852 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

~120–490KB
~12K SLoC