Skip to content

Commit

Permalink
Rust 2018 (#153)
Browse files Browse the repository at this point in the history
* ⬆️ Rust 2018 edition
  • Loading branch information
punkstarman authored Sep 3, 2021
1 parent 3101016 commit c34fe99
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 65 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ license = "MIT"
name = "serde-xml-rs"
repository = "https://github.com/RReverser/serde-xml-rs"
version = "0.5.0"
edition = "2018"

[dependencies]
log = "0.4"
Expand Down
3 changes: 2 additions & 1 deletion src/de/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use error::Result;
use crate::error::Result;
use crate::debug_expect;
use std::{collections::VecDeque, io::Read};
use xml::reader::{EventReader, XmlEvent};

Expand Down
7 changes: 4 additions & 3 deletions src/de/map.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use std::io::Read;

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

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

use super::buffer::BufferedXmlReader;

pub struct MapAccess<'a, R: 'a + Read, B: BufferedXmlReader<R>> {
pub struct MapAccess<'a, R: Read, B: BufferedXmlReader<R>> {
attrs: ::std::vec::IntoIter<OwnedAttribute>,
/// Cache of attribute value, populated when visitor calls `next_key_seed`; should be read & emptied straight after
/// by visitor call to `next_value_seed`
Expand Down
5 changes: 4 additions & 1 deletion src/de/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use std::{io::Read, marker::PhantomData};

use serde::forward_to_deserialize_any;
use serde::de::{self, Unexpected};
use log::debug;
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 error::{Error, Result};
use crate::{debug_expect, expect};
use crate::error::{Error, Result};

mod buffer;
mod map;
Expand Down
7 changes: 4 additions & 3 deletions src/de/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use std::io::Read;
use serde::de;
use xml::reader::XmlEvent;

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

pub struct SeqAccess<'a, R: 'a + Read> {
pub struct SeqAccess<'a, R: Read> {
de: ChildDeserializer<'a, R>,
max_size: Option<usize>,
seq_type: SeqType,
Expand Down
9 changes: 5 additions & 4 deletions src/de/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use serde::de::{self, Deserializer as SerdeDeserializer, IntoDeserializer};
use xml::name::OwnedName;
use xml::reader::XmlEvent;

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

use super::buffer::BufferedXmlReader;

pub struct EnumAccess<'a, R: 'a + Read, B: BufferedXmlReader<R>> {
pub struct EnumAccess<'a, R: Read, B: BufferedXmlReader<R>> {
de: &'a mut Deserializer<R, B>,
}

Expand Down Expand Up @@ -40,7 +41,7 @@ impl<'de, 'a, R: 'a + Read, B: BufferedXmlReader<R>> de::EnumAccess<'de> for Enu
}
}

pub struct VariantAccess<'a, R: 'a + Read, B: BufferedXmlReader<R>> {
pub struct VariantAccess<'a, R: Read, B: BufferedXmlReader<R>> {
de: &'a mut Deserializer<R, B>,
}

Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub enum Error {

pub type Result<T> = std::result::Result<T, Error>;

#[macro_export]
macro_rules! expect {
($actual: expr, $($expected: pat)|+ => $if_ok: expr) => {
match $actual {
Expand All @@ -64,6 +65,7 @@ macro_rules! expect {
}

#[cfg(debug_assertions)]
#[macro_export]
macro_rules! debug_expect {
($actual: expr, $($expected: pat)|+ => $if_ok: expr) => {
match $actual {
Expand All @@ -78,6 +80,7 @@ macro_rules! debug_expect {
}

#[cfg(not(debug_assertions))]
#[macro_export]
macro_rules! debug_expect {
($actual: expr, $($expected: pat)|+ => $if_ok: expr) => {
match $actual {
Expand Down
19 changes: 3 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,11 @@
//! }
//! ```
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde;
extern crate xml;

extern crate thiserror;

#[cfg(test)]
#[macro_use]
extern crate serde_derive;

#[macro_use]
mod error;
pub mod de;
pub mod ser;

pub use de::{from_reader, from_str, Deserializer};
pub use error::Error;
pub use ser::{to_string, to_writer, Serializer};
pub use crate::de::{from_reader, from_str, Deserializer};
pub use crate::error::Error;
pub use crate::ser::{to_string, to_writer, Serializer};
pub use xml::reader::{EventReader, ParserConfig};
3 changes: 2 additions & 1 deletion src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::Write;
use serde::ser::{self, Impossible, Serialize};

use self::var::{Map, Struct};
use error::{Error, Result};
use crate::error::{Error, Result};

mod var;

Expand Down Expand Up @@ -292,6 +292,7 @@ mod tests {
use super::*;
use serde::ser::{SerializeMap, SerializeStruct};
use serde::Serializer as SerSerializer;
use serde_derive::Serialize;

#[test]
fn test_serialize_bool() {
Expand Down
8 changes: 4 additions & 4 deletions src/ser/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::io::Write;

use serde::ser::{self, Serialize};

use error::{Error, Result};
use ser::Serializer;
use crate::error::{Error, Result};
use crate::ser::Serializer;

/// An implementation of `SerializeMap` for serializing to XML.
pub struct Map<'w, W>
where
W: 'w + Write,
W: Write,
{
parent: &'w mut Serializer<W>,
}
Expand Down Expand Up @@ -64,7 +64,7 @@ where
/// An implementation of `SerializeStruct` for serializing to XML.
pub struct Struct<'w, W>
where
W: 'w + Write,
W: Write,
{
parent: &'w mut Serializer<W>,
name: &'w str,
Expand Down
10 changes: 2 additions & 8 deletions tests/failures.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#[macro_use]
extern crate serde_derive;
extern crate serde_xml_rs;

#[macro_use]
extern crate log;
extern crate simple_logger;

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 Down
10 changes: 1 addition & 9 deletions tests/migrated.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
#[macro_use]
extern crate serde_derive;

extern crate log;
extern crate simple_logger;

extern crate serde;
extern crate serde_xml_rs;

use simple_logger::SimpleLogger;
use std::fmt::Debug;

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

fn init_logger() {
Expand Down
2 changes: 1 addition & 1 deletion tests/readme.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate docmatic;
use docmatic;

#[test]
fn test_readme() {
Expand Down
8 changes: 2 additions & 6 deletions tests/round_trip.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_xml_rs;

use serde::Deserialize;
use serde_xml_rs::{from_str, to_string, EventReader, ParserConfig};
use serde_derive::{Serialize, Deserialize};
use serde_xml_rs::{self, from_str, to_string, EventReader, ParserConfig};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Item {
Expand Down
9 changes: 1 addition & 8 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_xml_rs;

extern crate log;
extern crate simple_logger;

use serde::Deserialize;
use serde_derive::Deserialize;
use serde_xml_rs::{from_str, Deserializer};
use simple_logger::SimpleLogger;

Expand Down

0 comments on commit c34fe99

Please sign in to comment.