AssertOrder

Trait AssertOrder 

Source
pub trait AssertOrder<E> {
    // Required methods
    fn is_less_than(self, expected: E) -> Self;
    fn is_greater_than(self, expected: E) -> Self;
    fn is_at_most(self, expected: E) -> Self;
    fn is_at_least(self, expected: E) -> Self;
    fn is_before(self, expected: E) -> Self;
    fn is_after(self, expected: E) -> Self;
    fn is_between(self, min: E, max: E) -> Self;
}
Expand description

Assert whether a value is greater than or less than another value, as well as at most as big or at least as big as another value.

These assertions are implemented for all types that implement PartialOrd<E> with E being the type of the expected value the subject is being compared to.

§Examples

use time::macros::date;
use asserting::prelude::*;

let some_result: u16 = 42;

assert_that!(some_result).is_at_most(43);
assert_that!(some_result).is_at_most(42);
assert_that!(some_result).is_at_least(42);
assert_that!(some_result).is_at_least(41);
assert_that!(some_result).is_greater_than(41);
assert_that!(some_result).is_less_than(43);

let some_letter: char = 'M';

assert_that!(some_letter).is_before('P');
assert_that!(some_letter).is_after('K');
assert_that!(some_letter).is_between('A', 'Z');

let some_date = date!(2025-04-20);

assert_that!(some_date).is_before(date!(2025-04-21));
assert_that!(some_date).is_after(date!(2025-04-19));
assert_that!(some_date).is_between(date!(2025-04-19), date!(2025-04-21));

Required Methods§

Source

fn is_less_than(self, expected: E) -> Self

Verifies that the subject is less than some expected value.

§Examples
use asserting::prelude::*;

assert_that!(4).is_less_than(5);
assert_that!(-1).is_less_than(1);
assert_that!(-2).is_less_than(-1);
assert_that!(0.5).is_less_than(1.0);
Source

fn is_greater_than(self, expected: E) -> Self

Verifies that the subject is greater than some expected value.

§Examples
use asserting::prelude::*;

assert_that!(5).is_greater_than(4);
assert_that!(1).is_greater_than(-1);
assert_that!(-1).is_greater_than(-2);
assert_that!(0.5).is_greater_than(0.1);
Source

fn is_at_most(self, expected: E) -> Self

Verifies that the subject is less than or equal to some expected value.

§Examples
use asserting::prelude::*;

assert_that!(4).is_at_most(5);
assert_that!(5).is_at_most(5);
assert_that!(-2).is_at_most(-1);
assert_that!(-2).is_at_most(-2);
assert_that!(0.9).is_at_most(1.0);
Source

fn is_at_least(self, expected: E) -> Self

Verifies that the subject is greater than or equal to some expected value.

§Examples
use asserting::prelude::*;

assert_that!(5).is_at_least(4);
assert_that!(5).is_at_least(5);
assert_that!(-1).is_at_least(-2);
assert_that!(-2).is_at_least(-2);
assert_that!(1.4).is_at_least(1.0);
Source

fn is_before(self, expected: E) -> Self

Verifies that the subject is before some expected value.

This is equivalent to asserting a subject to be less than the expected value.

§Examples
use asserting::prelude::*;

assert_that!('M').is_before('N');
assert_that!(4).is_before(5);
assert_that!(0.8).is_before(1.0);

use time::macros::date;

assert_that!(date!(2025-05-30)).is_before(date!(2025-06-01));
Source

fn is_after(self, expected: E) -> Self

Verifies that the subject is after some expected value.

This is equivalent to asserting a subject to be greater than the expected value.

§Examples
use asserting::prelude::*;

assert_that!('N').is_after('M');
assert_that!(5).is_after(4);
assert_that!(1.2).is_after(1.0);

use time::macros::date;

assert_that!(date!(2025-06-01)).is_after(date!(2025-05-30));
Source

fn is_between(self, min: E, max: E) -> Self

Verifies that the subject is between a min value and a max value.

Min and max values are included. This is equivalent to asserting a subject to be greater than or equal to the min value and to be less than or equal to the max value.

§Examples
use asserting::prelude::*;

assert_that!('B').is_between('A', 'C');
assert_that!(5).is_between(4, 6);
assert_that!(1.5).is_between(0.9, 1.8);

use time::macros::date;

assert_that!(date!(2025-06-01)).is_between(date!(2025-05-30), date!(2025-06-02));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S, E, R> AssertOrder<E> for Spec<'_, S, R>
where S: PartialOrd<E> + Debug, E: Debug, R: FailingStrategy,