Here is the complete list of the implemented assertions. Note that the assertions marked as consuming consume the left part of the assertion, so there cannot be a chain of multiple assertions.
Those assertions print a more complete error message in the test functions marked as #[fact] or #[attribute]. They can be used in a standard #[test] function as well, but in this case, the location and the stringified version of the left side are not displayed in the failure message.
Various feature
Negation
(2 + 2).should().not().be_equal_to(5);
Chaining
"42".parse::<i32>().should().not().be_an_error()
.and_should().contain(42);
Explanation
the_answer().should().be_equal_to(42).because("42 is the answer to the question");
Equality
(1 + 1).should().be_equal_to(2);
With precision (for floats only):
(0.999 * 2.).should().be_equal_to(2.01).with_precision(0.1);
Iterators (consuming assertions)
Containing something
Some(2).should().contain(2);
vec![1, 2, 3].should().contain(1);
Checking if empty
let empty_vec = Vec::<i32>::new();
empty_vec.should().be_empty();
Results
Checking if it is an error
"?".parse::<i32>().should().be_an_error();
Generic
When there is no specific needed assertion:
foo().should().have_the_property(|&n| n % 2 == 0)
.because("the number must be even");