forked from assert-rs/predicates-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow predicates to own object and evaluate against borrowed types
It is very useful to be able to dynamically construct an object and have that object owned by the predicate, yet evaluate against an unowned type related to the owned one. An obvious example is a String being owned by the predicate but being compared against &strs. Therefore, implement Predicate for Eq/OrdPredicate that store an object that implements Borrow for the predicate type, replacing existing impls of Predicate<T> for Eq/OrdPredicate<T> and Eq/OrdPredicate<&T>. This is backwards compatible as there are blanket implementations of Borrow<T> for T and Borrow<T> for &T. Note that Borrow imposes more requirements than are actually required and AsRef would be sufficient. However, AsRef doesn't have a blanket implementation for T and thus the existing impl of Predicate<T> for EqPredicate<T> is still required, but results in a conflict since T may also implement AsRef<T>. Requiring Borrow instead of AsRef is sufficient for common use cases though. This addresses assert-rs#20 more completely.
- Loading branch information
Showing
1 changed file
with
31 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters