Skip to content

Commit

Permalink
🎨
Browse files Browse the repository at this point in the history
  • Loading branch information
punkstarman committed Sep 3, 2021
1 parent 42341d6 commit 6902657
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 37 deletions.
1 change: 0 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
match_block_trailing_comma = true
14 changes: 7 additions & 7 deletions src/de/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::Result;
use crate::debug_expect;
use crate::error::Result;
use std::{collections::VecDeque, io::Read};
use xml::reader::{EventReader, XmlEvent};

Expand Down Expand Up @@ -86,21 +86,21 @@ impl<'parent, R: Read> BufferedXmlReader<R> for ChildXmlBuffer<'parent, R> {
};

return debug_expect!(taken, CachedXmlEvent::Unused(ev) => Ok(ev));
},
}
Some(CachedXmlEvent::Used) => {
debug_assert!(
self.cursor != 0,
"Event buffer should not start with 'used' slot (should have been popped)"
);
self.cursor += 1;
continue;
},
}
None => {
debug_assert_eq!(self.buffer.len(), self.cursor);

// Skip creation of buffer entry when consuming event straight away
return next_significant_event(&mut self.reader);
},
}
}
}
}
Expand Down Expand Up @@ -143,11 +143,11 @@ fn get_from_buffer_or_reader<'buf>(
Some(CachedXmlEvent::Unused(_)) => break,
Some(CachedXmlEvent::Used) => {
*index += 1;
},
}
None => {
let next = next_significant_event(reader)?;
buffer.push_back(CachedXmlEvent::Unused(next));
},
}
}
}

Expand All @@ -162,7 +162,7 @@ fn next_significant_event(reader: &mut EventReader<impl Read>) -> Result<XmlEven
XmlEvent::StartDocument { .. }
| XmlEvent::ProcessingInstruction { .. }
| XmlEvent::Whitespace { .. }
| XmlEvent::Comment(_) => { /* skip */ },
| XmlEvent::Comment(_) => { /* skip */ }
other => return Ok(other),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/de/map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::io::Read;

use serde::forward_to_deserialize_any;
use serde::de::{self, IntoDeserializer, Unexpected};
use serde::forward_to_deserialize_any;
use xml::attribute::OwnedAttribute;
use xml::reader::XmlEvent;

Expand Down Expand Up @@ -46,7 +46,7 @@ impl<'de, 'a, R: 'a + Read, B: BufferedXmlReader<R>> de::MapAccess<'de> for MapA
self.next_attr_value = Some(value);
seed.deserialize(name.local_name.into_deserializer())
.map(Some)
},
}
None => match *self.de.peek()? {
XmlEvent::StartElement { ref name, .. } => seed
.deserialize(
Expand Down Expand Up @@ -77,7 +77,7 @@ impl<'de, 'a, R: 'a + Read, B: BufferedXmlReader<R>> de::MapAccess<'de> for MapA
}
let result = seed.deserialize(&mut *self.de)?;
Ok(result)
},
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use std::{io::Read, marker::PhantomData};

use serde::forward_to_deserialize_any;
use serde::de::{self, Unexpected};
use log::debug;
use serde::de::{self, Unexpected};
use serde::forward_to_deserialize_any;
use xml::name::OwnedName;
use xml::reader::{EventReader, ParserConfig, XmlEvent};

use self::buffer::{BufferedXmlReader, ChildXmlBuffer, RootXmlBuffer};
use self::map::MapAccess;
use self::seq::SeqAccess;
use self::var::EnumAccess;
use crate::{debug_expect, expect};
use crate::error::{Error, Result};
use crate::{debug_expect, expect};

mod buffer;
mod map;
Expand Down Expand Up @@ -175,11 +175,11 @@ impl<'de, R: Read, B: BufferedXmlReader<R>> Deserializer<R, B> {
match next {
XmlEvent::StartElement { .. } => {
self.depth += 1;
},
}
XmlEvent::EndElement { .. } => {
self.depth -= 1;
},
_ => {},
}
_ => {}
}
debug!("Fetched {:?}", next);
Ok(next)
Expand Down
22 changes: 11 additions & 11 deletions src/de/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::io::Read;
use serde::de;
use xml::reader::XmlEvent;

use crate::debug_expect;
use crate::de::ChildDeserializer;
use crate::debug_expect;
use crate::error::{Error, Result};

pub struct SeqAccess<'a, R: Read> {
Expand Down Expand Up @@ -53,11 +53,11 @@ impl<'de, 'a, R: 'a + Read> de::SeqAccess<'de> for SeqAccess<'a, R> {
match self.max_size.as_mut() {
Some(&mut 0) => {
return Ok(None);
},
}
Some(max_size) => {
*max_size -= 1;
},
None => {},
}
None => {}
}

match &self.seq_type {
Expand All @@ -84,34 +84,34 @@ impl<'de, 'a, R: 'a + Read> de::SeqAccess<'de> for SeqAccess<'a, R> {
} else {
return Ok(None);
}
},
}
XmlEvent::EndElement { .. } => {
if local_depth == 0 {
return Ok(None);
} else {
local_depth -= 1;
self.de.buffered_reader.skip();
}
},
}
XmlEvent::EndDocument => {
return Ok(None);
},
}
_ => {
self.de.buffered_reader.skip();
},
}
}
}
},
}
SeqType::AllMembers => {
let next_element = self.de.peek()?;

match next_element {
XmlEvent::EndElement { .. } | XmlEvent::EndDocument => return Ok(None),
_ => {
return seed.deserialize(&mut self.de).map(Some);
},
}
}
},
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/de/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use serde::de::{self, Deserializer as SerdeDeserializer, IntoDeserializer};
use xml::name::OwnedName;
use xml::reader::XmlEvent;

use crate::expect;
use crate::de::Deserializer;
use crate::error::{Error, Result};
use crate::expect;

use super::buffer::BufferedXmlReader;

Expand Down Expand Up @@ -67,7 +67,7 @@ impl<'de, 'a, R: 'a + Read, B: BufferedXmlReader<R>> de::VariantAccess<'de>
} else {
Err(de::Error::invalid_length(attributes.len(), &"0"))
}
},
}
XmlEvent::Characters(_) => Ok(()),
_ => unreachable!(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
//! }
//! ```
mod error;
pub mod de;
mod error;
pub mod ser;

pub use crate::de::{from_reader, from_str, Deserializer};
Expand Down
8 changes: 4 additions & 4 deletions tests/failures.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use log::info;
use serde_derive::Deserialize;
use serde_xml_rs::from_str;
use simple_logger::SimpleLogger;
use serde_derive::Deserialize;
use log::info;

fn init_logger() {
let _ = SimpleLogger::new().init();
Expand All @@ -27,7 +27,7 @@ fn simple_struct_from_attributes_should_fail() {
Err(e) => {
info!("simple_struct_from_attributes_should_fail(): {}", e);
assert!(true)
},
}
}
}

Expand All @@ -46,6 +46,6 @@ fn multiple_roots_attributes_should_fail() {
Err(e) => {
info!("multiple_roots_attributes_should_fail(): {}", e);
assert!(true)
},
}
}
}
2 changes: 1 addition & 1 deletion tests/migrated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use simple_logger::SimpleLogger;
use std::fmt::Debug;

use serde::{de, ser};
use serde_derive::{Serialize, Deserialize};
use serde_derive::{Deserialize, Serialize};
use serde_xml_rs::{from_str, Error};

fn init_logger() {
Expand Down
2 changes: 1 addition & 1 deletion tests/round_trip.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::Deserialize;
use serde_derive::{Serialize, Deserialize};
use serde_derive::{Deserialize, Serialize};
use serde_xml_rs::{self, from_str, to_string, EventReader, ParserConfig};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
Expand Down

0 comments on commit 6902657

Please sign in to comment.