From fa8b9ed199c7256ad5a9d5b53ba630be85cdfe93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 2 Apr 2020 22:42:28 +0200 Subject: [PATCH] minidom: rustfmt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- minidom-rs/src/element.rs | 35 +++++++++++++++++++-------- minidom-rs/src/error.rs | 5 +--- minidom-rs/src/lib.rs | 2 +- minidom-rs/src/node.rs | 8 ++++-- minidom-rs/src/tests.rs | 51 ++++++++++++++++++++++++--------------- 5 files changed, 64 insertions(+), 37 deletions(-) diff --git a/minidom-rs/src/element.rs b/minidom-rs/src/element.rs index 00e92a9..30c440a 100644 --- a/minidom-rs/src/element.rs +++ b/minidom-rs/src/element.rs @@ -15,8 +15,8 @@ use crate::convert::IntoAttributeValue; use crate::error::{Error, Result}; use crate::namespaces::NSChoice; -use crate::prefixes::{Prefix, Namespace, Prefixes}; use crate::node::Node; +use crate::prefixes::{Namespace, Prefix, Prefixes}; use std::collections::{btree_map, BTreeMap}; use std::io::Write; @@ -178,7 +178,7 @@ impl Element { None, None, BTreeMap::new(), - Vec::new() + Vec::new(), ), } } @@ -456,7 +456,11 @@ impl Element { } /// Like `write_to()` but without the `` prelude - pub fn write_to_inner(&self, writer: &mut EventWriter, all_prefixes: &mut BTreeMap) -> Result<()> { + pub fn write_to_inner( + &self, + writer: &mut EventWriter, + all_prefixes: &mut BTreeMap, + ) -> Result<()> { let local_prefixes: &BTreeMap, String> = self.prefixes.declared_prefixes(); // Element namespace @@ -485,7 +489,7 @@ impl Element { } (Some(format!("ns{}", prefix_n)), true) } - }, + } // Some prefix has already been declared (or is going to be) for our namespace. We // don't need to declare a new one. We do however need to remember which one to use in // the tag name. @@ -509,7 +513,7 @@ impl Element { let key = format!("xmlns"); start.push_attribute((key.as_bytes(), self.namespace.as_bytes())); all_prefixes.insert(self_prefix.0, self.namespace.clone()); - }, + } _ => (), }; @@ -525,7 +529,7 @@ impl Element { start.push_attribute((key.as_bytes(), ns.as_ref())); all_prefixes.insert(prefix.clone(), ns.clone()); - }, + } } } @@ -834,7 +838,11 @@ fn split_element_name>(s: S) -> Result<(Option, String)> { } } -fn build_element(reader: &EventReader, event: &BytesStart, prefixes: &mut BTreeMap) -> Result { +fn build_element( + reader: &EventReader, + event: &BytesStart, + prefixes: &mut BTreeMap, +) -> Result { let (prefix, name) = split_element_name(str::from_utf8(event.name())?)?; let mut local_prefixes = BTreeMap::new(); @@ -879,7 +887,7 @@ fn build_element(reader: &EventReader, event: &BytesStart, prefix Some(prefix), local_prefixes, attributes, - Vec::new() + Vec::new(), )) } @@ -994,7 +1002,11 @@ pub struct ElementBuilder { impl ElementBuilder { /// Sets a custom prefix. It is not possible to set the same prefix twice. - pub fn prefix>(mut self, prefix: Prefix, namespace: S) -> Result { + pub fn prefix>( + mut self, + prefix: Prefix, + namespace: S, + ) -> Result { if let Some(_) = self.root.prefixes.get(&prefix) { return Err(Error::DuplicatePrefix); } @@ -1102,7 +1114,10 @@ mod tests { assert_eq!(elem.name(), String::from("bar")); assert_eq!(elem.ns(), String::from("ns1")); // Ensure the prefix is properly added to the store - assert_eq!(elem.prefixes.get(&Some(String::from("foo"))), Some(&String::from("ns1"))); + assert_eq!( + elem.prefixes.get(&Some(String::from("foo"))), + Some(&String::from("ns1")) + ); } #[test] diff --git a/minidom-rs/src/error.rs b/minidom-rs/src/error.rs index 2510f4b..b34375a 100644 --- a/minidom-rs/src/error.rs +++ b/minidom-rs/src/error.rs @@ -80,10 +80,7 @@ impl std::fmt::Display for Error { } Error::InvalidElement => write!(fmt, "the XML element is invalid"), Error::InvalidPrefix => write!(fmt, "the prefix is invalid"), - Error::MissingNamespace => write!( - fmt, - "the XML element is missing a namespace", - ), + Error::MissingNamespace => write!(fmt, "the XML element is missing a namespace",), Error::NoComments => write!( fmt, "a comment has been found even though comments are forbidden" diff --git a/minidom-rs/src/lib.rs b/minidom-rs/src/lib.rs index bc47a2f..864519b 100644 --- a/minidom-rs/src/lib.rs +++ b/minidom-rs/src/lib.rs @@ -80,8 +80,8 @@ pub mod convert; pub mod element; pub mod error; mod namespaces; -mod prefixes; pub mod node; +mod prefixes; #[cfg(test)] mod tests; diff --git a/minidom-rs/src/node.rs b/minidom-rs/src/node.rs index 0a0615c..5d827e0 100644 --- a/minidom-rs/src/node.rs +++ b/minidom-rs/src/node.rs @@ -11,8 +11,8 @@ use crate::element::{Element, ElementBuilder}; use crate::error::Result; -use std::io::Write; use std::collections::BTreeMap; +use std::io::Write; use quick_xml::events::{BytesText, Event}; use quick_xml::Writer as EventWriter; @@ -160,7 +160,11 @@ impl Node { } #[doc(hidden)] - pub(crate) fn write_to_inner(&self, writer: &mut EventWriter, prefixes: &mut BTreeMap, String>) -> Result<()> { + pub(crate) fn write_to_inner( + &self, + writer: &mut EventWriter, + prefixes: &mut BTreeMap, String>, + ) -> Result<()> { match *self { Node::Element(ref elmt) => elmt.write_to_inner(writer, prefixes)?, Node::Text(ref s) => { diff --git a/minidom-rs/src/tests.rs b/minidom-rs/src/tests.rs index 6190e65..726379f 100644 --- a/minidom-rs/src/tests.rs +++ b/minidom-rs/src/tests.rs @@ -49,12 +49,17 @@ fn reader_deduplicate_prefixes() { // parent ns with the same prefix. let _: Element = r#""#.parse().unwrap(); let _: Element = r#""#.parse().unwrap(); - let _: Element = r#""#.parse().unwrap(); + let _: Element = r#""# + .parse() + .unwrap(); match r#""#.parse::() { Err(Error::MissingNamespace) => (), Err(err) => panic!("No or wrong error: {:?}", err), - Ok(elem) => panic!("Got Element: {}; was expecting Error::MissingNamespace", String::from(&elem)), + Ok(elem) => panic!( + "Got Element: {}; was expecting Error::MissingNamespace", + String::from(&elem) + ), } } @@ -64,7 +69,11 @@ fn reader_no_deduplicate_sibling_prefixes() { match r#""#.parse::() { Err(Error::MissingNamespace) => (), Err(err) => panic!("No or wrong error: {:?}", err), - Ok(elem) => panic!("Got Element:\n{:?}\n{}\n; was expecting Error::MissingNamespace", elem, String::from(&elem)), + Ok(elem) => panic!( + "Got Element:\n{:?}\n{}\n; was expecting Error::MissingNamespace", + elem, + String::from(&elem) + ), } } @@ -156,7 +165,8 @@ fn writer_with_prefix() { .prefix(None, "ns2") .unwrap() .build(); - assert_eq!(String::from(&root), + assert_eq!( + String::from(&root), r#""#, ); } @@ -183,7 +193,10 @@ fn writer_no_prefix_namespace_child() { .build(); let root = Element::builder("root", "ns1").append(child).build(); // TODO: Same remark as `writer_no_prefix_namespace`. - assert_eq!(String::from(&root), r#""#); + assert_eq!( + String::from(&root), + r#""# + ); } #[test] @@ -194,7 +207,10 @@ fn writer_prefix_namespace_child() { .unwrap() .append(child) .build(); - assert_eq!(String::from(&root), r#""#); + assert_eq!( + String::from(&root), + r#""# + ); } #[test] @@ -209,7 +225,8 @@ fn writer_with_prefix_deduplicate() { .unwrap() .append(child) .build(); - assert_eq!(String::from(&root), + assert_eq!( + String::from(&root), r#""#, ); @@ -245,7 +262,10 @@ fn writer_escapes_text() { { root.write_to(&mut writer).unwrap(); } - assert_eq!(String::from_utf8(writer).unwrap(), r#"<3"#); + assert_eq!( + String::from_utf8(writer).unwrap(), + r#"<3"# + ); } #[test] @@ -363,10 +383,7 @@ fn namespace_prefixed() { .parse() .unwrap(); assert_eq!(elem.name(), "features"); - assert_eq!( - elem.ns(), - "http://etherx.jabber.org/streams".to_owned(), - ); + assert_eq!(elem.ns(), "http://etherx.jabber.org/streams".to_owned(),); } #[test] @@ -386,10 +403,7 @@ fn namespace_inherited_prefixed1() { let elem: Element = "" .parse().unwrap(); assert_eq!(elem.name(), "features"); - assert_eq!( - elem.ns(), - "http://etherx.jabber.org/streams".to_owned(), - ); + assert_eq!(elem.ns(), "http://etherx.jabber.org/streams".to_owned(),); let child = elem.children().next().unwrap(); assert_eq!(child.name(), "message"); assert_eq!(child.ns(), "jabber:client".to_owned()); @@ -400,10 +414,7 @@ fn namespace_inherited_prefixed2() { let elem: Element = "" .parse().unwrap(); assert_eq!(elem.name(), "stream"); - assert_eq!( - elem.ns(), - "http://etherx.jabber.org/streams".to_owned(), - ); + assert_eq!(elem.ns(), "http://etherx.jabber.org/streams".to_owned(),); let child = elem.children().next().unwrap(); assert_eq!(child.name(), "message"); assert_eq!(child.ns(), "jabber:client".to_owned());