From 8c2d6a8463dd00ee956d196914b65d6b235e5992 Mon Sep 17 00:00:00 2001 From: Edward Barnard Date: Fri, 16 Mar 2018 11:09:05 +0000 Subject: Run rustfmt. --- src/xml/reader.rs | 48 +++++++++++++++++++++++++--------------------- src/xml/writer.rs | 57 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 56 insertions(+), 49 deletions(-) (limited to 'src/xml') diff --git a/src/xml/reader.rs b/src/xml/reader.rs index 66fd8f1..c1c2b3b 100644 --- a/src/xml/reader.rs +++ b/src/xml/reader.rs @@ -3,7 +3,7 @@ use std::io::Read; use std::str::FromStr; use xml_rs::reader::{EventReader as XmlEventReader, ParserConfig, XmlEvent}; -use {Date, Error, Result, PlistEvent}; +use {Date, Error, PlistEvent, Result}; pub struct EventReader { xml_reader: XmlEventReader, @@ -30,7 +30,8 @@ impl EventReader { } fn read_content(&mut self, f: F) -> Result - where F: FnOnce(String) -> Result + where + F: FnOnce(String) -> Result, { match self.xml_reader.next() { Ok(XmlEvent::Characters(s)) => f(s), @@ -66,7 +67,8 @@ impl EventReader { "false" => return Some(Ok(PlistEvent::BooleanValue(false))), "data" => { return Some(self.read_content(|s| { - let data = base64::decode_config(&s, base64::MIME).map_err(|_| Error::InvalidData)?; + let data = base64::decode_config(&s, base64::MIME) + .map_err(|_| Error::InvalidData)?; Ok(PlistEvent::DataValue(data)) })) } @@ -161,25 +163,27 @@ mod tests { let streaming_parser = EventReader::new(reader); let events: Vec = streaming_parser.map(|e| e.unwrap()).collect(); - let comparison = &[StartDictionary(None), - StringValue("Author".to_owned()), - StringValue("William Shakespeare".to_owned()), - StringValue("Lines".to_owned()), - StartArray(None), - StringValue("It is a tale told by an idiot,".to_owned()), - StringValue("Full of sound and fury, signifying nothing.".to_owned()), - EndArray, - StringValue("Death".to_owned()), - IntegerValue(1564), - StringValue("Height".to_owned()), - RealValue(1.60), - StringValue("Data".to_owned()), - DataValue(vec![0, 0, 0, 190, 0, 0, 0, 3, 0, 0, 0, 30, 0, 0, 0]), - StringValue("Birthdate".to_owned()), - DateValue(Date::from_chrono(Utc.ymd(1981, 05, 16).and_hms(11, 32, 06))), - StringValue("Blank".to_owned()), - StringValue("".to_owned()), - EndDictionary]; + let comparison = &[ + StartDictionary(None), + StringValue("Author".to_owned()), + StringValue("William Shakespeare".to_owned()), + StringValue("Lines".to_owned()), + StartArray(None), + StringValue("It is a tale told by an idiot,".to_owned()), + StringValue("Full of sound and fury, signifying nothing.".to_owned()), + EndArray, + StringValue("Death".to_owned()), + IntegerValue(1564), + StringValue("Height".to_owned()), + RealValue(1.60), + StringValue("Data".to_owned()), + DataValue(vec![0, 0, 0, 190, 0, 0, 0, 3, 0, 0, 0, 30, 0, 0, 0]), + StringValue("Birthdate".to_owned()), + DateValue(Date::from_chrono(Utc.ymd(1981, 05, 16).and_hms(11, 32, 06))), + StringValue("Blank".to_owned()), + StringValue("".to_owned()), + EndDictionary, + ]; assert_eq!(events, comparison); } diff --git a/src/xml/writer.rs b/src/xml/writer.rs index ffb8aa4..77ccd87 100644 --- a/src/xml/writer.rs +++ b/src/xml/writer.rs @@ -4,7 +4,7 @@ use std::io::Write; use xml_rs::attribute::Attribute; use xml_rs::name::Name; use xml_rs::namespace::Namespace; -use xml_rs::writer::{Error as XmlWriterError, EventWriter as XmlEventWriter, EmitterConfig}; +use xml_rs::writer::{EmitterConfig, Error as XmlWriterError, EventWriter as XmlEventWriter}; use xml_rs::writer::events::XmlEvent as WriteXmlEvent; use {Error, EventWriter as PlistEventWriter, PlistEvent, Result}; @@ -72,7 +72,9 @@ impl EventWriter { } fn end_element(&mut self, name: &str) -> Result<()> { - self.xml_writer.write(WriteXmlEvent::EndElement { name: Some(Name::local(name)) })?; + self.xml_writer.write(WriteXmlEvent::EndElement { + name: Some(Name::local(name)), + })?; Ok(()) } @@ -105,7 +107,8 @@ impl PlistEventWriter for EventWriter { match *event { PlistEvent::StringValue(ref value) => { self.write_element_and_value("key", &*value)?; - self.stack.push(Element::Dictionary(DictionaryState::ExpectValue)); + self.stack + .push(Element::Dictionary(DictionaryState::ExpectValue)); } PlistEvent::EndDictionary => { self.end_element("dict")?; @@ -116,9 +119,8 @@ impl PlistEventWriter for EventWriter { }; return Ok(()); } - Some(Element::Dictionary(DictionaryState::ExpectValue)) => { - self.stack.push(Element::Dictionary(DictionaryState::ExpectKey)) - } + Some(Element::Dictionary(DictionaryState::ExpectValue)) => self.stack + .push(Element::Dictionary(DictionaryState::ExpectKey)), Some(other) => self.stack.push(other), None => { let version_name = Name::local("version"); @@ -149,7 +151,8 @@ impl PlistEventWriter for EventWriter { PlistEvent::StartDictionary(_) => { self.start_element("dict")?; - self.stack.push(Element::Dictionary(DictionaryState::ExpectKey)); + self.stack + .push(Element::Dictionary(DictionaryState::ExpectKey)); } PlistEvent::EndDictionary => return Err(Error::InvalidData), @@ -174,9 +177,7 @@ impl PlistEventWriter for EventWriter { PlistEvent::RealValue(ref value) => { self.write_element_and_value("real", &value.to_string())? } - PlistEvent::StringValue(ref value) => { - self.write_element_and_value("string", &*value)? - } + PlistEvent::StringValue(ref value) => self.write_element_and_value("string", &*value)?, }; self.maybe_end_plist()?; @@ -197,23 +198,25 @@ mod tests { fn streaming_parser() { use PlistEvent::*; - let plist = &[StartDictionary(None), - StringValue("Author".to_owned()), - StringValue("William Shakespeare".to_owned()), - StringValue("Lines".to_owned()), - StartArray(None), - StringValue("It is a tale told by an idiot,".to_owned()), - StringValue("Full of sound and fury, signifying nothing.".to_owned()), - EndArray, - StringValue("Death".to_owned()), - IntegerValue(1564), - StringValue("Height".to_owned()), - RealValue(1.60), - StringValue("Data".to_owned()), - DataValue(vec![0, 0, 0, 190, 0, 0, 0, 3, 0, 0, 0, 30, 0, 0, 0]), - StringValue("Birthdate".to_owned()), - DateValue(Date::from_chrono(Utc.ymd(1981, 05, 16).and_hms(11, 32, 06))), - EndDictionary]; + let plist = &[ + StartDictionary(None), + StringValue("Author".to_owned()), + StringValue("William Shakespeare".to_owned()), + StringValue("Lines".to_owned()), + StartArray(None), + StringValue("It is a tale told by an idiot,".to_owned()), + StringValue("Full of sound and fury, signifying nothing.".to_owned()), + EndArray, + StringValue("Death".to_owned()), + IntegerValue(1564), + StringValue("Height".to_owned()), + RealValue(1.60), + StringValue("Data".to_owned()), + DataValue(vec![0, 0, 0, 190, 0, 0, 0, 3, 0, 0, 0, 30, 0, 0, 0]), + StringValue("Birthdate".to_owned()), + DateValue(Date::from_chrono(Utc.ymd(1981, 05, 16).and_hms(11, 32, 06))), + EndDictionary, + ]; let mut cursor = Cursor::new(Vec::new()); -- cgit v1.2.3