-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
Implement try_filter_entry
#134
base: master
Are you sure you want to change the base?
Conversation
0365e6c
to
67ffa46
Compare
I could add a |
Wow, okay, it looks like you put a lot of work into this. Unfortunately, the public API changes appear quite voluminous and it's not actually easy for me to tell at a glance whether there are any breaking changes. If this is really the only way to add Can you say why you diverged from my suggestion in #131? That is, can you just add a new |
I understand. I don't think I introduced any breaking changes, and the old tests still compile without any changes. That's what I tried to do, maybe I misunderstood: I duplicated
|
That would basically remove the |
Yeah I think the introduction of a new trait is what is concerning to me. But yeah, I agree, the lack of a trait makes composition impossible, which isn't great either. Not sure what to do. I'll have to noodle on it. |
I had to add a couple of traits to keep the crate usable, but made sure the user doesn't need to know about them.
It took me a couple of tries to land on the
TryFilterPredicate
trait, here's a breakdown of my thought process, maybe you'll have a better idea:The signature
fn filter_entry<P>(self, predicate: P) -> FilterEntry<Self, P>
has to useP
in the return type, so the predicate can't just be wrapped like|res| res.is_err() || predicate(res.unwrap())
otherwise we get an unnameable return type, having to use-> impl Trait
syntax which would break method chaining.I added the
TryFilterPredicate
trait and tried to implement it for bothFnMut(&DirEntry) -> bool
andFnMut(&Result<DirEntry>) -> bool
, but the compiler says they're conflicting implementations, I don't understand why and didn't find much on this.So next I tried to add
FilterPredicateAdapter<P: FnMut(&DirEntry) -> bool>
and implementFnMut(&Result<DirEntry>)
for it but that doesn't seem possible on stable yet.And finally I got it working by implementing
TryFilterPredicate
forFnMut(&Result<DirEntry>) -> bool
, and forFilterPredicateAdapter
.So now
FilterEntry
is defined asstruct FilterEntry<I, P>(TryFilterEntry<I, FilterPredicateAdapter<P>>)
.I'm still relatively new to writing rust, so please point out any changes I can make to improve the code, naming, docs, or anything else!