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

Support Equivalent trait for the cache key type K #492

Merged
merged 4 commits into from
Jan 19, 2025

Conversation

tatsuya6502
Copy link
Member

Summary

Support the Equivalent trait from the equivalent crate for the cache key type K. Replace all usages of the trait bound K: Borrow<Q> with Q: Equivalent<K>.

For example,

Before

pub fn get<Q>(&self, key: &Q) -> Option<V>
where
    K: Borrow<Q>,
    Q: Hash + Eq + ?Sized,

After

pub fn get<Q>(&self, key: &Q) -> Option<V>
where
    Q: Equivalent<K> + Hash + ?Sized,

https://github.com/indexmap-rs/equivalent/blob/master/README.md

These traits are not used by the maps in the standard library, but they may add more flexibility in third-party map implementations, especially in situations where a strict K: Borrow<Q> relationship is not available.

Changes

  • Add the equivalent crate to the dependencies.
  • Reexport the equivalent module.
  • Replace all trait bound K: Borrow<Q> with Q: Equivalent<K>.

Relates to #166

@tatsuya6502 tatsuya6502 added the enhancement New feature or request label Jan 16, 2025
@tatsuya6502 tatsuya6502 added this to the v0.12.11 milestone Jan 16, 2025
@tatsuya6502 tatsuya6502 self-assigned this Jan 16, 2025
Copy link

codecov bot commented Jan 16, 2025

Codecov Report

Attention: Patch coverage is 92.22222% with 7 lines in your changes missing coverage. Please review.

Project coverage is 94.17%. Comparing base (e9bcd86) to head (fd68e80).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #492      +/-   ##
==========================================
- Coverage   94.31%   94.17%   -0.15%     
==========================================
  Files          43       43              
  Lines       20492    20433      -59     
==========================================
- Hits        19328    19242      -86     
- Misses       1164     1191      +27     

Copy link
Member Author

@tatsuya6502 tatsuya6502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging.

@tatsuya6502 tatsuya6502 merged commit 2d932ef into main Jan 19, 2025
43 checks passed
@tatsuya6502 tatsuya6502 deleted the support-equivalent-trait branch January 19, 2025 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant