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

#1202 in Rust patterns

Download history 974/week @ 2024-11-16 814/week @ 2024-11-23 606/week @ 2024-11-30 593/week @ 2024-12-07 561/week @ 2024-12-14 583/week @ 2024-12-21 620/week @ 2024-12-28 650/week @ 2025-01-04 584/week @ 2025-01-11 687/week @ 2025-01-18 443/week @ 2025-01-25 670/week @ 2025-02-01 726/week @ 2025-02-08 639/week @ 2025-02-15 813/week @ 2025-02-22 727/week @ 2025-03-01

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

~200–630KB
~15K SLoC