#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

#2202 in Rust patterns

Download history 939/week @ 2024-11-21 687/week @ 2024-11-28 608/week @ 2024-12-05 573/week @ 2024-12-12 577/week @ 2024-12-19 481/week @ 2024-12-26 758/week @ 2025-01-02 620/week @ 2025-01-09 616/week @ 2025-01-16 585/week @ 2025-01-23 475/week @ 2025-01-30 781/week @ 2025-02-06 674/week @ 2025-02-13 686/week @ 2025-02-20 892/week @ 2025-02-27 1051/week @ 2025-03-06

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

~210–650KB
~15K SLoC