Skip to content

Commit 04922c7

Browse files
committed
Replace HashMap with BTreeMap to have a stable order of tags/attributes
1 parent c396d4b commit 04922c7

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

src/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,13 @@ impl Entry {
464464
/// # Examples
465465
///
466466
/// ```
467-
/// use std::collections::HashMap;
467+
/// use std::collections::BTreeMap;
468468
/// use atom_syndication::Entry;
469469
/// use atom_syndication::extension::{ExtensionMap, Extension};
470470
///
471471
/// let extension = Extension::default();
472472
///
473-
/// let mut item_map = HashMap::<String, Vec<Extension>>::new();
473+
/// let mut item_map = BTreeMap::<String, Vec<Extension>>::new();
474474
/// item_map.insert("ext:name".to_string(), vec![extension]);
475475
///
476476
/// let mut extension_map = ExtensionMap::default();

src/extension/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::BTreeMap;
22
use std::io::Write;
33
use std::str;
44

@@ -11,7 +11,7 @@ use crate::toxml::ToXml;
1111
pub(crate) mod util;
1212

1313
/// A map of extension namespace prefixes to local names to elements.
14-
pub type ExtensionMap = HashMap<String, HashMap<String, Vec<Extension>>>;
14+
pub type ExtensionMap = BTreeMap<String, BTreeMap<String, Vec<Extension>>>;
1515

1616
/// A namespaced extension.
1717
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
@@ -32,10 +32,10 @@ pub struct Extension {
3232
pub value: Option<String>,
3333
/// The attributes for the extension element.
3434
#[cfg_attr(feature = "builders", builder(setter(each = "attr")))]
35-
pub attrs: HashMap<String, String>,
35+
pub attrs: BTreeMap<String, String>,
3636
/// The children of the extension element. A map of local names to child elements.
3737
#[cfg_attr(feature = "builders", builder(setter(each = "child")))]
38-
pub children: HashMap<String, Vec<Extension>>,
38+
pub children: BTreeMap<String, Vec<Extension>>,
3939
}
4040

4141
impl Extension {
@@ -108,16 +108,16 @@ impl Extension {
108108
/// # Examples
109109
///
110110
/// ```
111-
/// use std::collections::HashMap;
111+
/// use std::collections::BTreeMap;
112112
/// use atom_syndication::extension::Extension;
113113
///
114114
/// let mut extension = Extension::default();
115-
/// let mut attrs = HashMap::<String, String>::new();
115+
/// let mut attrs = BTreeMap::<String, String>::new();
116116
/// attrs.insert("email".to_string(), "johndoe@example.com".to_string());
117117
/// extension.set_attrs(attrs.clone());
118118
/// assert_eq!(*extension.attrs(), attrs);
119119
/// ```
120-
pub fn attrs(&self) -> &HashMap<String, String> {
120+
pub fn attrs(&self) -> &BTreeMap<String, String> {
121121
&self.attrs
122122
}
123123

@@ -126,15 +126,15 @@ impl Extension {
126126
/// # Examples
127127
///
128128
/// ```
129-
/// use std::collections::HashMap;
129+
/// use std::collections::BTreeMap;
130130
/// use atom_syndication::extension::Extension;
131131
///
132132
/// let mut extension = Extension::default();
133-
/// extension.set_attrs(HashMap::new());
133+
/// extension.set_attrs(BTreeMap::new());
134134
/// ```
135135
pub fn set_attrs<V>(&mut self, attrs: V)
136136
where
137-
V: Into<HashMap<String, String>>,
137+
V: Into<BTreeMap<String, String>>,
138138
{
139139
self.attrs = attrs.into();
140140
}
@@ -146,16 +146,16 @@ impl Extension {
146146
/// # Examples
147147
///
148148
/// ```
149-
/// use std::collections::HashMap;
149+
/// use std::collections::BTreeMap;
150150
/// use atom_syndication::extension::Extension;
151151
///
152152
/// let mut extension = Extension::default();
153-
/// let mut children = HashMap::<String, Vec<Extension>>::new();
153+
/// let mut children = BTreeMap::<String, Vec<Extension>>::new();
154154
/// children.insert("ext:child".to_string(), Vec::new());
155155
/// extension.set_children(children);
156156
/// assert!(extension.children().contains_key("ext:child"));
157157
/// ```
158-
pub fn children(&self) -> &HashMap<String, Vec<Extension>> {
158+
pub fn children(&self) -> &BTreeMap<String, Vec<Extension>> {
159159
&self.children
160160
}
161161

@@ -166,15 +166,15 @@ impl Extension {
166166
/// # Examples
167167
///
168168
/// ```
169-
/// use std::collections::HashMap;
169+
/// use std::collections::BTreeMap;
170170
/// use atom_syndication::extension::Extension;
171171
///
172172
/// let mut extension = Extension::default();
173-
/// extension.set_children(HashMap::new());
173+
/// extension.set_children(BTreeMap::new());
174174
/// ```
175175
pub fn set_children<V>(&mut self, children: V)
176176
where
177-
V: Into<HashMap<String, Vec<Extension>>>,
177+
V: Into<BTreeMap<String, Vec<Extension>>>,
178178
{
179179
self.children = children.into();
180180
}

src/extension/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::BTreeMap;
22
use std::io::BufRead;
33
use std::str;
44

@@ -32,7 +32,7 @@ where
3232
let ext = parse_extension_element(reader, atts)?;
3333

3434
if !extensions.contains_key(ns) {
35-
extensions.insert(ns.to_string(), HashMap::new());
35+
extensions.insert(ns.to_string(), BTreeMap::new());
3636
}
3737

3838
let map = match extensions.get_mut(ns) {

src/feed.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::BTreeMap;
22
use std::io::{BufRead, Write};
33
use std::str::{self, FromStr};
44

@@ -70,7 +70,7 @@ pub struct Feed {
7070
pub extensions: ExtensionMap,
7171
/// The namespaces present in the feed tag.
7272
#[cfg_attr(feature = "builders", builder(setter(each = "namespace")))]
73-
pub namespaces: HashMap<String, String>,
73+
pub namespaces: BTreeMap<String, String>,
7474
}
7575

7676
impl Feed {
@@ -570,13 +570,13 @@ impl Feed {
570570
/// # Examples
571571
///
572572
/// ```
573-
/// use std::collections::HashMap;
573+
/// use std::collections::BTreeMap;
574574
/// use atom_syndication::Feed;
575575
/// use atom_syndication::extension::{ExtensionMap, Extension};
576576
///
577577
/// let extension = Extension::default();
578578
///
579-
/// let mut item_map = HashMap::<String, Vec<Extension>>::new();
579+
/// let mut item_map = BTreeMap::<String, Vec<Extension>>::new();
580580
/// item_map.insert("ext:name".to_string(), vec![extension]);
581581
///
582582
/// let mut extension_map = ExtensionMap::default();
@@ -617,17 +617,17 @@ impl Feed {
617617
/// # Examples
618618
///
619619
/// ```
620-
/// use std::collections::HashMap;
620+
/// use std::collections::BTreeMap;
621621
/// use atom_syndication::Feed;
622622
///
623-
/// let mut namespaces = HashMap::new();
623+
/// let mut namespaces = BTreeMap::new();
624624
/// namespaces.insert("ext".to_string(), "http://example.com".to_string());
625625
///
626626
/// let mut feed = Feed::default();
627627
/// feed.set_namespaces(namespaces);
628628
/// assert_eq!(feed.namespaces().get("ext").map(|s| s.as_str()), Some("http://example.com"));
629629
/// ```
630-
pub fn namespaces(&self) -> &HashMap<String, String> {
630+
pub fn namespaces(&self) -> &BTreeMap<String, String> {
631631
&self.namespaces
632632
}
633633

@@ -636,15 +636,15 @@ impl Feed {
636636
/// # Examples
637637
///
638638
/// ```
639-
/// use std::collections::HashMap;
639+
/// use std::collections::BTreeMap;
640640
/// use atom_syndication::Feed;
641641
///
642642
/// let mut feed = Feed::default();
643-
/// feed.set_namespaces(HashMap::new());
643+
/// feed.set_namespaces(BTreeMap::new());
644644
/// ```
645645
pub fn set_namespaces<V>(&mut self, namespaces: V)
646646
where
647-
V: Into<HashMap<String, String>>,
647+
V: Into<BTreeMap<String, String>>,
648648
{
649649
self.namespaces = namespaces.into()
650650
}
@@ -800,7 +800,7 @@ impl Default for Feed {
800800
subtitle: None,
801801
entries: Vec::new(),
802802
extensions: ExtensionMap::default(),
803-
namespaces: HashMap::default(),
803+
namespaces: BTreeMap::default(),
804804
}
805805
}
806806
}

tests/builders.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use atom_syndication::extension::*;
44
use atom_syndication::*;
5-
use std::collections::HashMap;
5+
use std::collections::BTreeMap;
66
use std::str::FromStr;
77

88
fn join_lines(text: &str) -> String {
@@ -79,7 +79,7 @@ fn test_builders() {
7979
.build(),
8080
)
8181
.extension(("ext".to_string(), {
82-
let mut map = HashMap::new();
82+
let mut map = BTreeMap::new();
8383
map.insert(
8484
"title".to_string(),
8585
vec![ExtensionBuilder::default()

0 commit comments

Comments
 (0)