Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow predicates to own object and evaluate against borrowed types #134

Merged
merged 2 commits into from Dec 29, 2022

Commits on Dec 29, 2022

  1. feat: Allow eq/ord predicates to own object and eval vs 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.
    rshearman committed Dec 29, 2022
    Copy the full SHA
    f9536e0 View commit details
    Browse the repository at this point in the history
  2. feat: Allow into_iter predicates to own object and eval vs borrowed t…

    …ypes
    
    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 In/OrdIn/HashInPredicate that store
    an object that implements Borrow for the predicate type, replacing
    existing impls of Predicate<T> for In/OrdIn/HashInPredicate<T> and
    In/OrdIn/HashInPredicate<&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
    InPredicate<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.
    rshearman committed Dec 29, 2022
    Copy the full SHA
    7934a3a View commit details
    Browse the repository at this point in the history