9 stable releases

1.3.0 Feb 15, 2025
1.2.1 Feb 15, 2025
1.0.0 Jan 31, 2025
0.1.2 Jan 31, 2025

#387 in Rust patterns

Download history 196/week @ 2025-01-26 402/week @ 2025-02-02 459/week @ 2025-02-09 188/week @ 2025-02-16 25/week @ 2025-02-23 16/week @ 2025-03-02

718 downloads per month
Used in 2 crates

MIT license

15KB
260 lines

This crate provides reusable error messages (PanicMsg) for use with panics, assertions (assert, assert_eq, assert_ne), and expect. It also includes debug versions of each of these methods (besides expect).

Simply declare a PanicMsg:

const EXAMPLE_PANIC: PanicMsg = PanicMsg::new("This is an example panic message.");

Then use it like this:

EXAMPLE_PANIC.panic();
// ...
EXAMPLE_PANIC.panic_if(left >= right);
// ...
EXAMPLE_PANIC.assert(left < right);
// ...
EXAMPLE_PANIC.assert_eq(left, right);
// ...
EXAMPLE_PANIC.assert_ne(left, right);
// ...
EXAMPLE_PANIC.expect(option);
// ...
EXAMPLE_PANIC.expect(result);
// ...
EXAMPLE_PANIC.debug_panic();
// ...
EXAMPLE_PANIC.debug_panic_if(left >= right);
// ...
EXAMPLE_PANIC.debug_assert(left < right);
// ...
EXAMPLE_PANIC.debug_assert_eq(left, right);
// ...
EXAMPLE_PANIC.debug_assert_ne(left, right);

lib.rs:

This crate provides reusable error messages ([PanicMsg]) for use with panics, assertions (assert, assert_eq, assert_ne), and expect. It also includes debug versions of each of these methods (except for expect).

Simply declare a [PanicMsg]:

const EXAMPLE_PANIC: PanicMsg = PanicMsg::new("This is an example panic message.");

Then use it like this:

EXAMPLE_PANIC.panic();
// ...
EXAMPLE_PANIC.panic_if(left >= right);
// ...
EXAMPLE_PANIC.assert(left < right);
// ...
EXAMPLE_PANIC.assert_eq(left, right);
// ...
EXAMPLE_PANIC.assert_ne(left, right);
// ...
EXAMPLE_PANIC.expect(option);
// ...
EXAMPLE_PANIC.expect(result);
// ...
EXAMPLE_PANIC.debug_panic();
// ...
EXAMPLE_PANIC.debug_panic_if(left >= right);
// ...
EXAMPLE_PANIC.debug_assert(left < right);
// ...
EXAMPLE_PANIC.debug_assert_eq(left, right);
// ...
EXAMPLE_PANIC.debug_assert_ne(left, right);

No runtime deps