Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Switch from linked-hash-map to indexmap
Browse files Browse the repository at this point in the history
Follow the footsteps of serde_json!

Closes #348
  • Loading branch information
alexcrichton committed Oct 25, 2019
1 parent 8995cef commit e9f5290
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ members = ['test-suite']

[dependencies]
serde = "1.0.97"
linked-hash-map = { version = "0.5", optional = true }
indexmap = { version = "1.0", optional = true }

[dev-dependencies]
serde_derive = "1.0"
Expand All @@ -33,4 +33,4 @@ default = []
# 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
# while preserving the order of map keys in the input.
preserve_order = ["linked-hash-map"]
preserve_order = ["indexmap"]
22 changes: 11 additions & 11 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::ops;
use std::collections::{btree_map, BTreeMap};

#[cfg(feature = "preserve_order")]
use linked_hash_map::{self, LinkedHashMap};
use indexmap::{self, IndexMap};

/// Represents a JSON key/value type.
pub struct Map<K, V> {
Expand All @@ -36,7 +36,7 @@ pub struct Map<K, V> {
#[cfg(not(feature = "preserve_order"))]
type MapImpl<K, V> = BTreeMap<K, V>;
#[cfg(feature = "preserve_order")]
type MapImpl<K, V> = LinkedHashMap<K, V>;
type MapImpl<K, V> = IndexMap<K, V>;

impl Map<String, Value> {
/// Makes a new empty Map.
Expand All @@ -63,7 +63,7 @@ impl Map<String, Value> {
#[inline]
pub fn with_capacity(capacity: usize) -> Self {
Map {
map: LinkedHashMap::with_capacity(capacity),
map: IndexMap::with_capacity(capacity),
}
}

Expand Down Expand Up @@ -145,7 +145,7 @@ impl Map<String, Value> {
S: Into<String>,
{
#[cfg(feature = "preserve_order")]
use linked_hash_map::Entry as EntryImpl;
use indexmap::map::Entry as EntryImpl;
#[cfg(not(feature = "preserve_order"))]
use std::collections::btree_map::Entry as EntryImpl;

Expand Down Expand Up @@ -397,12 +397,12 @@ pub struct OccupiedEntry<'a> {
#[cfg(not(feature = "preserve_order"))]
type VacantEntryImpl<'a> = btree_map::VacantEntry<'a, String, Value>;
#[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"))]
type OccupiedEntryImpl<'a> = btree_map::OccupiedEntry<'a, String, Value>;
#[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> {
/// Returns a reference to this entry's key.
Expand Down Expand Up @@ -512,7 +512,7 @@ pub struct Iter<'a> {
#[cfg(not(feature = "preserve_order"))]
type IterImpl<'a> = btree_map::Iter<'a, String, Value>;
#[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));

Expand All @@ -537,7 +537,7 @@ pub struct IterMut<'a> {
#[cfg(not(feature = "preserve_order"))]
type IterMutImpl<'a> = btree_map::IterMut<'a, String, Value>;
#[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));

Expand All @@ -562,7 +562,7 @@ pub struct IntoIter {
#[cfg(not(feature = "preserve_order"))]
type IntoIterImpl = btree_map::IntoIter<String, Value>;
#[cfg(feature = "preserve_order")]
type IntoIterImpl = linked_hash_map::IntoIter<String, Value>;
type IntoIterImpl = indexmap::map::IntoIter<String, Value>;

delegate_iterator!((IntoIter) => (String, Value));

Expand All @@ -576,7 +576,7 @@ pub struct Keys<'a> {
#[cfg(not(feature = "preserve_order"))]
type KeysImpl<'a> = btree_map::Keys<'a, String, Value>;
#[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);

Expand All @@ -590,6 +590,6 @@ pub struct Values<'a> {
#[cfg(not(feature = "preserve_order"))]
type ValuesImpl<'a> = btree_map::Values<'a, String, Value>;
#[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);

0 comments on commit e9f5290

Please sign in to comment.