diff options
| author | Edward Barnard | 2018-03-16 11:09:05 +0000 |
|---|---|---|
| committer | Edward Barnard | 2018-03-16 11:09:05 +0000 |
| commit | 8c2d6a8463dd00ee956d196914b65d6b235e5992 (patch) | |
| tree | b95599078518d8894fae217eec6377665ff97fde /src/xml | |
| parent | c91087906540c210bdb457b32fb976ce735b22f9 (diff) | |
| download | rust-plist-8c2d6a8463dd00ee956d196914b65d6b235e5992.tar.bz2 | |
Run rustfmt.
Diffstat (limited to 'src/xml')
| -rw-r--r-- | src/xml/reader.rs | 48 | ||||
| -rw-r--r-- | src/xml/writer.rs | 57 |
2 files changed, 56 insertions, 49 deletions
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<R: Read> { xml_reader: XmlEventReader<R>, @@ -30,7 +30,8 @@ impl<R: Read> EventReader<R> { } fn read_content<F>(&mut self, f: F) -> Result<PlistEvent> - where F: FnOnce(String) -> Result<PlistEvent> + where + F: FnOnce(String) -> Result<PlistEvent>, { match self.xml_reader.next() { Ok(XmlEvent::Characters(s)) => f(s), @@ -66,7 +67,8 @@ impl<R: Read> EventReader<R> { "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<PlistEvent> = 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<W: Write> EventWriter<W> { } 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<W: Write> PlistEventWriter for EventWriter<W> { 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<W: Write> PlistEventWriter for EventWriter<W> { }; 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<W: Write> PlistEventWriter for EventWriter<W> { 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<W: Write> PlistEventWriter for EventWriter<W> { 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()); |
