pub trait AssertOrderedElements {
type SingleElement;
type MultipleElements;
// Required methods
fn first_element(self) -> Self::SingleElement;
fn last_element(self) -> Self::SingleElement;
fn nth_element(self, n: usize) -> Self::SingleElement;
fn elements_at(
self,
indices: impl IntoIterator<Item = usize>,
) -> Self::MultipleElements;
}Expand description
Extract one or multiple elements of a collection or an iterator that yields its elements in a defined order to call assertions on the extracted elements.
Extraction is used to target the assertions on specific elements of a collection or an iterator, such as the first or last element.
See also the AssertOrderedElementsRef trait for extracting multiple
elements from the same ordered collection or iterator for individual
assertions.
§Examples
use asserting::prelude::*;
let subject = ["one", "two", "three", "four", "five"];
assert_that!(subject).first_element().is_equal_to("one");
assert_that!(subject).last_element().is_equal_to("five");
assert_that!(subject).nth_element(3).is_equal_to("four");
assert_that!(subject)
.elements_at([0, 2, 4])
.contains_exactly(["one", "three", "five"]);Required Associated Types§
Sourcetype SingleElement
type SingleElement
A spec-like type that contains a single element as the subject that is extracted from the iterator.
Usually this is a Spec<'a, T, R>.
Sourcetype MultipleElements
type MultipleElements
A spec-like type that contains multiple or all elements of an iterator as the subject.
Usually this is a Spec<'a, Vec<T>, R>.
Required Methods§
Sourcefn first_element(self) -> Self::SingleElement
fn first_element(self) -> Self::SingleElement
Sourcefn last_element(self) -> Self::SingleElement
fn last_element(self) -> Self::SingleElement
Sourcefn nth_element(self, n: usize) -> Self::SingleElement
fn nth_element(self, n: usize) -> Self::SingleElement
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 = ["one", "two", "three"];
assert_that!(subject).nth_element(0).is_equal_to("one");
assert_that!(subject).nth_element(1).is_equal_to("two");
assert_that!(subject).nth_element(2).is_equal_to("three");Sourcefn elements_at(
self,
indices: impl IntoIterator<Item = usize>,
) -> Self::MultipleElements
fn elements_at( self, indices: impl IntoIterator<Item = usize>, ) -> Self::MultipleElements
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".