3 releases

0.1.2 Jun 20, 2023
0.1.1 Jun 19, 2023
0.1.0 Jun 19, 2023

#559 in Testing

MIT/Apache

7KB

#[unimpl]

CI Crates.io

Better unimplemented! macro for function definitions.

This macro helps you iterate faster on your codebase giving you more accurate feedback on which functions were called during tests. It's most useful during development.

Without unimpl the exact reason needs to be specified explicitly otherwise the error message is too generic:

use panic_message::panic_message;

fn func(a: u32) -> u32 {
    unimplemented!();
}

let error = std::panic::catch_unwind(|| {
    func(42);
}).unwrap_err();

// in a bigger codebase it's not clear which function was called
assert_eq!(panic_message(&error), "not implemented");

With unimpl the function name is automatically attached to the error message and the function body can be completely omitted:

use unimpl::unimpl;
use panic_message::panic_message;

#[unimpl]
pub fn func(a: u32) -> u32; // function body is autogenerated

let error = std::panic::catch_unwind(|| {
    func(42);
}).unwrap_err();

// function name is automatically appended
assert_eq!(panic_message(&error), "not implemented: func");

The macro can also be used inside impl blocks:

use unimpl::unimpl;
use panic_message::panic_message;

struct X;

impl X {
    /// This is a func.
    #[unimpl]
    pub fn func(a: u32) -> u32;
}

let error = std::panic::catch_unwind(|| {
    X::func(42);
}).unwrap_err();

assert_eq!(panic_message(&error), "not implemented: func");

License

This project is licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~240–690KB
~16K SLoC