Switch from linked-hash-map to indexmap
Follow the footsteps of serde_json! Closes #348
This commit is contained in:
parent
e89d255cbf
commit
bf1c4ce44f
|
@ -21,7 +21,7 @@ members = ['test-suite']
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "1.0.97"
|
serde = "1.0.97"
|
||||||
linked-hash-map = { version = "0.5", optional = true }
|
indexmap = { version = "1.0", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
|
@ -33,4 +33,4 @@ default = []
|
||||||
# Use LinkedHashMap rather than BTreeMap as the map type of toml::Value.
|
# Use LinkedHashMap rather than BTreeMap as the map type of toml::Value.
|
||||||
# This allows data to be read into a Value and written back to a TOML string
|
# This allows data to be read into a Value and written back to a TOML string
|
||||||
# while preserving the order of map keys in the input.
|
# while preserving the order of map keys in the input.
|
||||||
preserve_order = ["linked-hash-map"]
|
preserve_order = ["indexmap"]
|
||||||
|
|
22
src/map.rs
22
src/map.rs
|
@ -26,7 +26,7 @@ use std::ops;
|
||||||
use std::collections::{btree_map, BTreeMap};
|
use std::collections::{btree_map, BTreeMap};
|
||||||
|
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
use linked_hash_map::{self, LinkedHashMap};
|
use indexmap::{self, IndexMap};
|
||||||
|
|
||||||
/// Represents a JSON key/value type.
|
/// Represents a JSON key/value type.
|
||||||
pub struct Map<K, V> {
|
pub struct Map<K, V> {
|
||||||
|
@ -36,7 +36,7 @@ pub struct Map<K, V> {
|
||||||
#[cfg(not(feature = "preserve_order"))]
|
#[cfg(not(feature = "preserve_order"))]
|
||||||
type MapImpl<K, V> = BTreeMap<K, V>;
|
type MapImpl<K, V> = BTreeMap<K, V>;
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
type MapImpl<K, V> = LinkedHashMap<K, V>;
|
type MapImpl<K, V> = IndexMap<K, V>;
|
||||||
|
|
||||||
impl Map<String, Value> {
|
impl Map<String, Value> {
|
||||||
/// Makes a new empty Map.
|
/// Makes a new empty Map.
|
||||||
|
@ -63,7 +63,7 @@ impl Map<String, Value> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_capacity(capacity: usize) -> Self {
|
pub fn with_capacity(capacity: usize) -> Self {
|
||||||
Map {
|
Map {
|
||||||
map: LinkedHashMap::with_capacity(capacity),
|
map: IndexMap::with_capacity(capacity),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ impl Map<String, Value> {
|
||||||
S: Into<String>,
|
S: Into<String>,
|
||||||
{
|
{
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
use linked_hash_map::Entry as EntryImpl;
|
use indexmap::map::Entry as EntryImpl;
|
||||||
#[cfg(not(feature = "preserve_order"))]
|
#[cfg(not(feature = "preserve_order"))]
|
||||||
use std::collections::btree_map::Entry as EntryImpl;
|
use std::collections::btree_map::Entry as EntryImpl;
|
||||||
|
|
||||||
|
@ -397,12 +397,12 @@ pub struct OccupiedEntry<'a> {
|
||||||
#[cfg(not(feature = "preserve_order"))]
|
#[cfg(not(feature = "preserve_order"))]
|
||||||
type VacantEntryImpl<'a> = btree_map::VacantEntry<'a, String, Value>;
|
type VacantEntryImpl<'a> = btree_map::VacantEntry<'a, String, Value>;
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
type VacantEntryImpl<'a> = linked_hash_map::VacantEntry<'a, String, Value>;
|
type VacantEntryImpl<'a> = indexmap::map::VacantEntry<'a, String, Value>;
|
||||||
|
|
||||||
#[cfg(not(feature = "preserve_order"))]
|
#[cfg(not(feature = "preserve_order"))]
|
||||||
type OccupiedEntryImpl<'a> = btree_map::OccupiedEntry<'a, String, Value>;
|
type OccupiedEntryImpl<'a> = btree_map::OccupiedEntry<'a, String, Value>;
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
type OccupiedEntryImpl<'a> = linked_hash_map::OccupiedEntry<'a, String, Value>;
|
type OccupiedEntryImpl<'a> = indexmap::map::OccupiedEntry<'a, String, Value>;
|
||||||
|
|
||||||
impl<'a> Entry<'a> {
|
impl<'a> Entry<'a> {
|
||||||
/// Returns a reference to this entry's key.
|
/// Returns a reference to this entry's key.
|
||||||
|
@ -512,7 +512,7 @@ pub struct Iter<'a> {
|
||||||
#[cfg(not(feature = "preserve_order"))]
|
#[cfg(not(feature = "preserve_order"))]
|
||||||
type IterImpl<'a> = btree_map::Iter<'a, String, Value>;
|
type IterImpl<'a> = btree_map::Iter<'a, String, Value>;
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
type IterImpl<'a> = linked_hash_map::Iter<'a, String, Value>;
|
type IterImpl<'a> = indexmap::map::Iter<'a, String, Value>;
|
||||||
|
|
||||||
delegate_iterator!((Iter<'a>) => (&'a String, &'a Value));
|
delegate_iterator!((Iter<'a>) => (&'a String, &'a Value));
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ pub struct IterMut<'a> {
|
||||||
#[cfg(not(feature = "preserve_order"))]
|
#[cfg(not(feature = "preserve_order"))]
|
||||||
type IterMutImpl<'a> = btree_map::IterMut<'a, String, Value>;
|
type IterMutImpl<'a> = btree_map::IterMut<'a, String, Value>;
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
type IterMutImpl<'a> = linked_hash_map::IterMut<'a, String, Value>;
|
type IterMutImpl<'a> = indexmap::map::IterMut<'a, String, Value>;
|
||||||
|
|
||||||
delegate_iterator!((IterMut<'a>) => (&'a String, &'a mut Value));
|
delegate_iterator!((IterMut<'a>) => (&'a String, &'a mut Value));
|
||||||
|
|
||||||
|
@ -562,7 +562,7 @@ pub struct IntoIter {
|
||||||
#[cfg(not(feature = "preserve_order"))]
|
#[cfg(not(feature = "preserve_order"))]
|
||||||
type IntoIterImpl = btree_map::IntoIter<String, Value>;
|
type IntoIterImpl = btree_map::IntoIter<String, Value>;
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
type IntoIterImpl = linked_hash_map::IntoIter<String, Value>;
|
type IntoIterImpl = indexmap::map::IntoIter<String, Value>;
|
||||||
|
|
||||||
delegate_iterator!((IntoIter) => (String, Value));
|
delegate_iterator!((IntoIter) => (String, Value));
|
||||||
|
|
||||||
|
@ -576,7 +576,7 @@ pub struct Keys<'a> {
|
||||||
#[cfg(not(feature = "preserve_order"))]
|
#[cfg(not(feature = "preserve_order"))]
|
||||||
type KeysImpl<'a> = btree_map::Keys<'a, String, Value>;
|
type KeysImpl<'a> = btree_map::Keys<'a, String, Value>;
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
type KeysImpl<'a> = linked_hash_map::Keys<'a, String, Value>;
|
type KeysImpl<'a> = indexmap::map::Keys<'a, String, Value>;
|
||||||
|
|
||||||
delegate_iterator!((Keys<'a>) => &'a String);
|
delegate_iterator!((Keys<'a>) => &'a String);
|
||||||
|
|
||||||
|
@ -590,6 +590,6 @@ pub struct Values<'a> {
|
||||||
#[cfg(not(feature = "preserve_order"))]
|
#[cfg(not(feature = "preserve_order"))]
|
||||||
type ValuesImpl<'a> = btree_map::Values<'a, String, Value>;
|
type ValuesImpl<'a> = btree_map::Values<'a, String, Value>;
|
||||||
#[cfg(feature = "preserve_order")]
|
#[cfg(feature = "preserve_order")]
|
||||||
type ValuesImpl<'a> = linked_hash_map::Values<'a, String, Value>;
|
type ValuesImpl<'a> = indexmap::map::Values<'a, String, Value>;
|
||||||
|
|
||||||
delegate_iterator!((Values<'a>) => &'a Value);
|
delegate_iterator!((Values<'a>) => &'a Value);
|
||||||
|
|
Loading…
Reference in a new issue