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
TryFilterPredicatetrait, 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 usePin 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 Traitsyntax which would break method chaining.I added the
TryFilterPredicatetrait and tried to implement it for bothFnMut(&DirEntry) -> boolandFnMut(&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
TryFilterPredicateforFnMut(&Result<DirEntry>) -> bool, and forFilterPredicateAdapter.So now
FilterEntryis 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!