Crates.io | unimpl |
lib.rs | unimpl |
version | 0.1.2 |
source | src |
created_at | 2023-06-19 09:49:45.929016 |
updated_at | 2023-06-20 15:59:17.50712 |
description | Better unimplemented! macro for function definitions |
homepage | |
repository | https://github.com/wiktor-k/unimpl |
max_upload_size | |
id | 893980 |
size | 17,864 |
#[unimpl]
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");
This project is licensed under either of:
at your option.
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.