diff --git a/src/entry.rs b/src/entry.rs index 7490ef1..df57dd8 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -464,13 +464,13 @@ impl Entry { /// # Examples /// /// ``` - /// use std::collections::HashMap; + /// use std::collections::BTreeMap; /// use atom_syndication::Entry; /// use atom_syndication::extension::{ExtensionMap, Extension}; /// /// let extension = Extension::default(); /// - /// let mut item_map = HashMap::>::new(); + /// let mut item_map = BTreeMap::>::new(); /// item_map.insert("ext:name".to_string(), vec![extension]); /// /// let mut extension_map = ExtensionMap::default(); diff --git a/src/extension/mod.rs b/src/extension/mod.rs index 41b8e0b..f4e9449 100644 --- a/src/extension/mod.rs +++ b/src/extension/mod.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::BTreeMap; use std::io::Write; use std::str; @@ -11,7 +11,7 @@ use crate::toxml::ToXml; pub(crate) mod util; /// A map of extension namespace prefixes to local names to elements. -pub type ExtensionMap = HashMap>>; +pub type ExtensionMap = BTreeMap>>; /// A namespaced extension. #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] @@ -32,10 +32,10 @@ pub struct Extension { pub value: Option, /// The attributes for the extension element. #[cfg_attr(feature = "builders", builder(setter(each = "attr")))] - pub attrs: HashMap, + pub attrs: BTreeMap, /// The children of the extension element. A map of local names to child elements. #[cfg_attr(feature = "builders", builder(setter(each = "child")))] - pub children: HashMap>, + pub children: BTreeMap>, } impl Extension { @@ -108,16 +108,16 @@ impl Extension { /// # Examples /// /// ``` - /// use std::collections::HashMap; + /// use std::collections::BTreeMap; /// use atom_syndication::extension::Extension; /// /// let mut extension = Extension::default(); - /// let mut attrs = HashMap::::new(); + /// let mut attrs = BTreeMap::::new(); /// attrs.insert("email".to_string(), "johndoe@example.com".to_string()); /// extension.set_attrs(attrs.clone()); /// assert_eq!(*extension.attrs(), attrs); /// ``` - pub fn attrs(&self) -> &HashMap { + pub fn attrs(&self) -> &BTreeMap { &self.attrs } @@ -126,15 +126,15 @@ impl Extension { /// # Examples /// /// ``` - /// use std::collections::HashMap; + /// use std::collections::BTreeMap; /// use atom_syndication::extension::Extension; /// /// let mut extension = Extension::default(); - /// extension.set_attrs(HashMap::new()); + /// extension.set_attrs(BTreeMap::new()); /// ``` pub fn set_attrs(&mut self, attrs: V) where - V: Into>, + V: Into>, { self.attrs = attrs.into(); } @@ -146,16 +146,16 @@ impl Extension { /// # Examples /// /// ``` - /// use std::collections::HashMap; + /// use std::collections::BTreeMap; /// use atom_syndication::extension::Extension; /// /// let mut extension = Extension::default(); - /// let mut children = HashMap::>::new(); + /// let mut children = BTreeMap::>::new(); /// children.insert("ext:child".to_string(), Vec::new()); /// extension.set_children(children); /// assert!(extension.children().contains_key("ext:child")); /// ``` - pub fn children(&self) -> &HashMap> { + pub fn children(&self) -> &BTreeMap> { &self.children } @@ -166,15 +166,15 @@ impl Extension { /// # Examples /// /// ``` - /// use std::collections::HashMap; + /// use std::collections::BTreeMap; /// use atom_syndication::extension::Extension; /// /// let mut extension = Extension::default(); - /// extension.set_children(HashMap::new()); + /// extension.set_children(BTreeMap::new()); /// ``` pub fn set_children(&mut self, children: V) where - V: Into>>, + V: Into>>, { self.children = children.into(); } diff --git a/src/extension/util.rs b/src/extension/util.rs index 9d1fc34..48806ae 100644 --- a/src/extension/util.rs +++ b/src/extension/util.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::BTreeMap; use std::io::BufRead; use std::str; @@ -32,7 +32,7 @@ where let ext = parse_extension_element(reader, atts)?; if !extensions.contains_key(ns) { - extensions.insert(ns.to_string(), HashMap::new()); + extensions.insert(ns.to_string(), BTreeMap::new()); } let map = match extensions.get_mut(ns) { diff --git a/src/feed.rs b/src/feed.rs index 97cc45f..c0b9855 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::BTreeMap; use std::io::{BufRead, Write}; use std::str::{self, FromStr}; @@ -70,7 +70,7 @@ pub struct Feed { pub extensions: ExtensionMap, /// The namespaces present in the feed tag. #[cfg_attr(feature = "builders", builder(setter(each = "namespace")))] - pub namespaces: HashMap, + pub namespaces: BTreeMap, } impl Feed { @@ -570,13 +570,13 @@ impl Feed { /// # Examples /// /// ``` - /// use std::collections::HashMap; + /// use std::collections::BTreeMap; /// use atom_syndication::Feed; /// use atom_syndication::extension::{ExtensionMap, Extension}; /// /// let extension = Extension::default(); /// - /// let mut item_map = HashMap::>::new(); + /// let mut item_map = BTreeMap::>::new(); /// item_map.insert("ext:name".to_string(), vec![extension]); /// /// let mut extension_map = ExtensionMap::default(); @@ -617,17 +617,17 @@ impl Feed { /// # Examples /// /// ``` - /// use std::collections::HashMap; + /// use std::collections::BTreeMap; /// use atom_syndication::Feed; /// - /// let mut namespaces = HashMap::new(); + /// let mut namespaces = BTreeMap::new(); /// namespaces.insert("ext".to_string(), "http://example.com".to_string()); /// /// let mut feed = Feed::default(); /// feed.set_namespaces(namespaces); /// assert_eq!(feed.namespaces().get("ext").map(|s| s.as_str()), Some("http://example.com")); /// ``` - pub fn namespaces(&self) -> &HashMap { + pub fn namespaces(&self) -> &BTreeMap { &self.namespaces } @@ -636,15 +636,15 @@ impl Feed { /// # Examples /// /// ``` - /// use std::collections::HashMap; + /// use std::collections::BTreeMap; /// use atom_syndication::Feed; /// /// let mut feed = Feed::default(); - /// feed.set_namespaces(HashMap::new()); + /// feed.set_namespaces(BTreeMap::new()); /// ``` pub fn set_namespaces(&mut self, namespaces: V) where - V: Into>, + V: Into>, { self.namespaces = namespaces.into() } @@ -800,7 +800,7 @@ impl Default for Feed { subtitle: None, entries: Vec::new(), extensions: ExtensionMap::default(), - namespaces: HashMap::default(), + namespaces: BTreeMap::default(), } } } diff --git a/tests/builders.rs b/tests/builders.rs index b6fd675..d18176c 100644 --- a/tests/builders.rs +++ b/tests/builders.rs @@ -2,7 +2,7 @@ use atom_syndication::extension::*; use atom_syndication::*; -use std::collections::HashMap; +use std::collections::BTreeMap; use std::str::FromStr; fn join_lines(text: &str) -> String { @@ -79,7 +79,7 @@ fn test_builders() { .build(), ) .extension(("ext".to_string(), { - let mut map = HashMap::new(); + let mut map = BTreeMap::new(); map.insert( "title".to_string(), vec![ExtensionBuilder::default()