English | 简体中文
Inspired by indexmap-rs/equivalent, providing Equivalent and Comparable, which are Rust traits for key comparison in maps, but flips K and Q.
-
Why this crate?
Rust's compiler cannot infur types in some cases(by using [
indexmap-rs/equivalent]) and users have to add turbofish, the details can be found in https://github.com/indexmap-rs/equivalent/issues/5 or https://github.com/crossbeam-rs/crossbeam/pull/1132.
These may be used in the implementation of maps where the lookup type Q
may be different than the stored key type K.
K: Equivalent<Q>, Q: ?Sizedchecks for equality, similar to theHashMap<K, V>constraintK: Borrow<Q>, Q: Eq.K: Comparable<Q>, Q: ?Sizedchecks the ordering, similar to theBTreeMap<K, V>constraintK: Borrow<Q>, Q: Ord.
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.
Installation
[]
= "0.1"
Pedigree
This code is inspired and modified based on indexmap-rs/equivalent, and reference to @cuviper attempts on https://github.com/indexmap-rs/indexmap/issues/253#issuecomment-1459160166
License
equivalent-flipped is under the terms of both the MIT license and the
Apache License (Version 2.0).
See LICENSE-APACHE, LICENSE-MIT for details.
Copyright (c) 2024 Al Liu.