-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A feature-flag to change maps representation to BTreeMap
As of now, maps are represented with [std::collections::HashMap](https://doc.rust-lang.org/stable/std/collections/struct.HashMap.html), which serves as a robust default. In rarer instances, opting for a different implementation, such as BTreeMap, might be desirable, e.g. for deterministic serialization (#496). This change * adds `btreemaps` feature flags which changes maps to be backed by [std::collections::BTreeMap](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html).
- Loading branch information
Showing
12 changed files
with
87 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "btreemaps")] { | ||
/// Rust type to map protobuf maps into. | ||
pub type Map<K, V> = std::collections::BTreeMap<K, V>; | ||
|
||
/// Key constraints for `Map`. BTreeMap keys must implement `Ord` | ||
pub trait KeyConstraint: Ord {} | ||
impl<T: Ord> KeyConstraint for T {} | ||
|
||
/// Iterator type of `Map` | ||
pub(crate) type Iter<'a, K, V> = std::collections::btree_map::Iter<'a, K, V>; | ||
} else { | ||
/// Rust type to map protobuf maps into. | ||
pub type Map<K, V> = std::collections::HashMap<K, V>; | ||
|
||
/// Key constraints for `Map`. HashMap keys must implement `std::hash::Hash` | ||
pub trait KeyConstraint: std::hash::Hash {} | ||
impl<T: std::hash::Hash> KeyConstraint for T {} | ||
|
||
/// Iterator type of `Map` | ||
pub(crate) type Iter<'a, K, V> = std::collections::hash_map::Iter<'a, K, V>; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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