pub trait AssertOrderedElements<'a, T, R> {
// Required methods
fn first_element(self) -> Spec<'a, T, R>;
fn last_element(self) -> Spec<'a, T, R>;
fn nth_element(self, n: usize) -> Spec<'a, T, R>;
fn elements_at(
self,
indices: impl IntoIterator<Item = usize>,
) -> Spec<'a, Vec<T>, R>;
}Expand description
Filter assertions for elements of a collection or an iterator that yields its elements in a defined order.
Filtering is used to target the assertions on specific elements of a collection or an iterator, such as the first or last element.
§Examples
use asserting::prelude::*;
let subject = ["first", "second", "third", "four", "five"];
assert_that!(subject).first_element().is_equal_to("first");
assert_that!(subject).last_element().is_equal_to("five");
assert_that!(subject).nth_element(3).is_equal_to("four");
let subject = ["one", "two", "three", "four", "five"];
assert_that!(subject)
.elements_at([0, 2, 4])
.contains_exactly(["one", "three", "five"]);Required Methods§
Sourcefn first_element(self) -> Spec<'a, T, R>
fn first_element(self) -> Spec<'a, T, R>
Sourcefn last_element(self) -> Spec<'a, T, R>
fn last_element(self) -> Spec<'a, T, R>
Sourcefn nth_element(self, n: usize) -> Spec<'a, T, R>
fn nth_element(self, n: usize) -> Spec<'a, T, R>
Verify that a collection or an iterator contains at least n + 1 elements
and return a Spec for the nth element.
The index n is zero-based (similar to the nth method of iterators).
§Examples
use asserting::prelude::*;
let subject = ["first", "second", "third"];
assert_that!(subject).nth_element(0).is_equal_to("first");
assert_that!(subject).nth_element(1).is_equal_to("second");
assert_that!(subject).nth_element(2).is_equal_to("third");Sourcefn elements_at(
self,
indices: impl IntoIterator<Item = usize>,
) -> Spec<'a, Vec<T>, R>
fn elements_at( self, indices: impl IntoIterator<Item = usize>, ) -> Spec<'a, Vec<T>, R>
Pick the elements of a collection or an iterator at the given positions
and return a Spec only containing the selected elements.
§Examples
use asserting::prelude::*;
let subject = ["one", "two", "three", "four", "five"];
assert_that!(subject)
.elements_at([0, 2, 4])
.contains_exactly(["one", "three", "five"]);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.