Skip to main content

OkPredicateAssertion

Trait OkPredicateAssertion 

Source
pub trait OkPredicateAssertion<T> {
    // Required methods
    fn should_be_ok_and_satisfy<F: Fn(&T) -> bool>(&self, predicate: F) -> &Self;
    fn should_be_ok_and_not_satisfy<F: Fn(&T) -> bool>(
        &self,
        predicate: F,
    ) -> &Self;
}
Expand description

OkPredicateAssertion enables assertions about whether the Result value is both Ok and that the contained value meets or doesn’t meet certain conditions defined by a predicate.

Required Methods§

Source

fn should_be_ok_and_satisfy<F: Fn(&T) -> bool>(&self, predicate: F) -> &Self

  • Asserts that the Result value is Ok and satisfies the given predicate.
  • Returns a reference to self for fluent chaining.
  • Panics if the assertion fails.
§Example
use clearcheck::assertions::result::predicate::OkPredicateAssertion;

let value: Result<i32, &str> = Ok(1000);
value.should_be_ok_and_satisfy(|value| value > &50);
Source

fn should_be_ok_and_not_satisfy<F: Fn(&T) -> bool>(&self, predicate: F) -> &Self

  • Asserts that the Result value is Ok and does not satisfy the given predicate.
  • Returns a reference to self for fluent chaining.
  • Panics if the assertion fails.
§Example
use clearcheck::assertions::result::predicate::OkPredicateAssertion;

let value: Result<i32, &str> = Ok(100);
value.should_be_ok_and_not_satisfy(|value| value > &500);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, E> OkPredicateAssertion<T> for Result<T, E>

Source§

fn should_be_ok_and_satisfy<F: Fn(&T) -> bool>(&self, predicate: F) -> &Self

Source§

fn should_be_ok_and_not_satisfy<F: Fn(&T) -> bool>(&self, predicate: F) -> &Self

Implementors§