unimpl

Crates.iounimpl
lib.rsunimpl
version0.1.2
sourcesrc
created_at2023-06-19 09:49:45.929016
updated_at2023-06-20 15:59:17.50712
descriptionBetter unimplemented! macro for function definitions
homepage
repositoryhttps://github.com/wiktor-k/unimpl
max_upload_size
id893980
size17,864
Heiko Schaefer (hko-s)

documentation

README

#[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.

Commit count: 1

cargo fmt