Skip to main content

Crate perl_test_must

Crate perl_test_must 

Source
Expand description

Safe unwrap replacements for tests.

This crate provides panic-on-failure helpers that are safe to use in tests, avoiding explicit unwrap() calls which are denied by clippy policy.

§Overview

Three helpers cover the common cases:

  • must — extract the value from a Result, or panic with the error
  • must_some — extract the value from an Option, or panic
  • must_err — extract the error from a Result, or panic if Ok

§Example

use perl_test_must::{must, must_some, must_err};

let result: Result<i32, &str> = Ok(42);
assert_eq!(must(result), 42);

let opt: Option<i32> = Some(7);
assert_eq!(must_some(opt), 7);

let err_result: Result<i32, &str> = Err("oops");
assert_eq!(must_err(err_result), "oops");

Functions§

must
Extract the value from a Result, or panic with the error.
must_err
Extract the error from a Result, or panic if Ok.
must_some
Extract the value from an Option, or panic.