Offer RawExtractIf as hash_{table,map}::Extractor#683
Offer RawExtractIf as hash_{table,map}::Extractor#683clarfonthey wants to merge 1 commit intorust-lang:masterfrom
RawExtractIf as hash_{table,map}::Extractor#683Conversation
Amanieu
left a comment
There was a problem hiding this comment.
I like the concept, but I don't think the lack of TAIT is the only reason to add this. A more flexible version of ExtractIf has been requested several times via #599 and #588.
Regarding the API I see 2 ways to go about it:
- Something which takes a filter closure like you have right now.
- Something which looks more like a cursor, like what I proposed in #599 (comment).
Both approaches have trade-offs and it might be worth considering whether they address all possible use cases.
| } | ||
|
|
||
| /// Returns the equivalent of [`Iterator::size_hint`] for the extractor. | ||
| pub fn size_hint(&self) -> (usize, Option<usize>) { |
There was a problem hiding this comment.
Since we can always precisely determined how many items remain, this should be called remaining_elements or something similar and just return a usize.
There was a problem hiding this comment.
That's fair; my main thought process here was to make the API as close to Iterator as possible minus the closure. I'll make that change.
| impl<'a, T, A: Allocator> Extractor<'a, T, A> { | ||
| /// Extracts elements from the table based upon a function. | ||
| /// | ||
| /// This can be used to implement [`Iterator::next`]. |
There was a problem hiding this comment.
This needs a more complete description of what the closure parameter means and what the Some/None return values mean.
|
I actually do like the cursor idea better, although it would require a bit more refactoring than what I have provided right now. Will poke around that at some point. |
|
Going to close this right now since cursors seem like the right approach, but the API should probably be properly designed. Will post a separate issue about it. |
Essentially, until TAIT (rust-lang/rust#63063) is stable, we're going to need some form of
RawExtractIfinternally, and so will external users if they want to wrap their tables in a special way. So, let's actually make the API public under the nameExtractor.This is also the last bit needed to make
HashSetnot depend on the raw table implementation, being fully implemented viaHashMap.