Add indexing methods to raw entry#305
Merged
cuviper merged 2 commits intoindexmap-rs:masterfrom Jan 31, 2024
Merged
Conversation
The `std`-matching methods of `RawEntryBuilder` only return `(&K, &V)`,
but the index is also useful when working with `IndexMap`.
```rust
impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
/// Access an entry by hash, including its index.
pub fn from_hash_full<F>(self, hash: u64, is_match: F) -> Option<(usize, &'a K, &'a V)>
where
F: FnMut(&K) -> bool,
/// Access the index of an entry by hash.
pub fn index_from_hash<F>(self, hash: u64, is_match: F) -> Option<usize>
where
F: FnMut(&K) -> bool,
}
```
In addition, the `RawEntryMut` enum can report its index by forwarding
to the existing methods on its variants.
```rust
impl<'a, K, V, S> RawEntryMut<'a, K, V, S> {
/// Return the index where the key-value pair exists or may be inserted.
pub fn index(&self) -> usize
}
```
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
std-matching methods ofRawEntryBuilderonly return(&K, &V),but the index is also useful when working with
IndexMap.In addition, the
RawEntryMutenum can report its index by forwardingto the existing methods on its variants.