pub trait CollectionAssertion<T> {
// Required methods
fn be_empty(self) -> Self;
fn not_be_empty(self) -> Self;
fn have_length(self, length: usize) -> Self;
fn contain(self, expected: &T) -> Self
where T: PartialEq;
}Expand description
Specific assertions for list-like collections (Vec, arrays and slices).
These live on a trait rather than being inherent methods because the string
assertions are implemented for the blanket impl<T: AsRef<str>> Assertion<T>.
Coherence conservatively assumes Vec<_> / &[_] might implement
AsRef<str> in the future, so inherent methods sharing the same names
(be_empty, contain, …) would clash with the string impl. A trait sidesteps
that: it is implemented only for the concrete Assertion<Vec<T>>,
Assertion<&[T]>, Assertion<[T; N]> and Assertion<&Vec<T>>, never for
&str / String.
Required Methods§
Sourcefn be_empty(self) -> Self
fn be_empty(self) -> Self
Asserts that the collection is empty
§Examples
use fluent_assertions::*;
Vec::<i32>::new().should().be_empty();Sourcefn not_be_empty(self) -> Self
fn not_be_empty(self) -> Self
Asserts that the collection is not empty
§Examples
use fluent_assertions::*;
vec![1, 2, 3].should().not_be_empty();Sourcefn have_length(self, length: usize) -> Self
fn have_length(self, length: usize) -> Self
Asserts that the collection has a given length
§Examples
use fluent_assertions::*;
[1, 2, 3].should().have_length(3);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".