Crate coerce_pattern

Crate coerce_pattern 

Source
Expand description

This crate contains two proc macros relating to asserting, under penalty of panic, that expressions match patterns.

  1. coerce_pattern! matches an expression to a target pattern and evaluates to an expression of the inner variables from the pattern, panicking if the pattern doesn’t match
  2. assert_pattern! matches an expression to a target and panics if the pattern doesn’t match.

To use them, run the following command in your project directory.

cargo add coerce_pattern

Then, you can use the macros using

use coerce_pattern::{coerce_pattern, assert_pattern};

See below for detailed documentation on the macros.

Macros§

assert_pattern
Asserts that an expression matches a pattern, like a generalized assert!(result.is_ok()).
coerce_pattern
Coerces an expression into a pattern, like a generalized unwrap.