Crates.io | equivalent-flipped |
lib.rs | equivalent-flipped |
version | |
source | src |
created_at | 2024-12-11 13:16:02.727373 |
updated_at | 2024-12-11 13:45:59.29388 |
description | Similar to `equivalent` crate, but flips `K` and `Q`. |
homepage | https://github.com/al8n/equivalent-flipped |
repository | https://github.com/al8n/equivalent-flipped |
max_upload_size | |
id | 1480077 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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: ?Sized
checks for equality, similar to the HashMap<K, V>
constraint K: Borrow<Q>, Q: Eq
.K: Comparable<Q>, Q: ?Sized
checks the ordering, similar to the BTreeMap<K, V>
constraint K: 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.
[dependencies]
equivalent-flipped = "0.1"
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
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.