Skip to content

feat: remove trait bound DefinedOrderProperty from iterator assertions - #97

Merged
haraldmaida merged 2 commits into
mainfrom
feat/remove-ordered-iterator-constraint
Sep 6, 2026
Merged

feat: remove trait bound DefinedOrderProperty from iterator assertions#97
haraldmaida merged 2 commits into
mainfrom
feat/remove-ordered-iterator-constraint

Conversation

@haraldmaida

@haraldmaida haraldmaida commented Sep 6, 2026

Copy link
Copy Markdown
Member

Assertions on iterators such as .contains_exactly (in order) or .first_element() only make sense on iterators that yield the elements in a well defined order. Therefore we defined the DefinedOrderProperty trait to make all iterators that yield their elements in a well defined order and allow the users to write assertions that rely on a well defined order only for iterators that implement the DefinedOrderProperty trait. In practice this turned out to be more painful than helpful.

The problem with this design:

Currently when we want to write an assertion for a "composite" iterator where we know the elements are yielded in a well defined order, the compiler prevents us from doing so. The trait DefinedOrderProperty is not implemented for Map or Skip or Take.

The following example won't compile, although we know the elements are yielded in the same order as defined in the array:

let subject = ["one", "two", "three", "four"];
let iterator = subject.into_iter().skip(1).take(2);

assert_that!(iterator).contains_exactly(["two", "three"]);

The solution:

We remove the trait bounds on DefinedOrderProperty from the assertion-methods for iterators.

The drawback is, that we can now use .contains_exactly also on hashsets and other types that yield the elements in an undefined order. The test might be flaky, because sometimes the order is as expected and sometimes it is not. So it is up to the user to carefully choose the right assertion method.

With this pull request the trait bounds on DefinedOderProperty are removed from all assertion methods for iterators.

@haraldmaida haraldmaida self-assigned this Sep 6, 2026
@haraldmaida haraldmaida added the enhancement New feature or request label Sep 6, 2026
@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.84%. Comparing base (52dc9c0) to head (08e6039).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #97   +/-   ##
=======================================
  Coverage   87.84%   87.84%           
=======================================
  Files          42       42           
  Lines        7513     7513           
  Branches     7513     7513           
=======================================
  Hits         6600     6600           
  Misses        843      843           
  Partials       70       70           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@haraldmaida
haraldmaida merged commit 5423488 into main Sep 6, 2026
20 checks passed
@haraldmaida
haraldmaida deleted the feat/remove-ordered-iterator-constraint branch September 6, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant