From c34fe998609a9315498850d7013d0ecc5c43e84e Mon Sep 17 00:00:00 2001 From: William Bartlett Date: Fri, 3 Sep 2021 21:19:17 +0200 Subject: [PATCH] Rust 2018 (#153) * :arrow_up: Rust 2018 edition --- Cargo.toml | 1 + src/de/buffer.rs | 3 ++- src/de/map.rs | 7 ++++--- src/de/mod.rs | 5 ++++- src/de/seq.rs | 7 ++++--- src/de/var.rs | 9 +++++---- src/error.rs | 3 +++ src/lib.rs | 19 +++---------------- src/ser/mod.rs | 3 ++- src/ser/var.rs | 8 ++++---- tests/failures.rs | 10 ++-------- tests/migrated.rs | 10 +--------- tests/readme.rs | 2 +- tests/round_trip.rs | 8 ++------ tests/test.rs | 9 +-------- 15 files changed, 39 insertions(+), 65 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 06b4c19..92fc357 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/de/buffer.rs b/src/de/buffer.rs index 24c5e94..ab13ff7 100644 --- a/src/de/buffer.rs +++ b/src/de/buffer.rs @@ -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}; diff --git a/src/de/map.rs b/src/de/map.rs index 79f7985..24c5616 100644 --- a/src/de/map.rs +++ b/src/de/map.rs @@ -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> { +pub struct MapAccess<'a, R: Read, B: BufferedXmlReader> { attrs: ::std::vec::IntoIter, /// Cache of attribute value, populated when visitor calls `next_key_seed`; should be read & emptied straight after /// by visitor call to `next_value_seed` diff --git a/src/de/mod.rs b/src/de/mod.rs index 7ea1768..11646e3 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -1,6 +1,8 @@ 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}; @@ -8,7 +10,8 @@ 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; diff --git a/src/de/seq.rs b/src/de/seq.rs index 51b7978..eb20e05 100644 --- a/src/de/seq.rs +++ b/src/de/seq.rs @@ -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, seq_type: SeqType, diff --git a/src/de/var.rs b/src/de/var.rs index 7a82204..cd3e72c 100644 --- a/src/de/var.rs +++ b/src/de/var.rs @@ -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> { +pub struct EnumAccess<'a, R: Read, B: BufferedXmlReader> { de: &'a mut Deserializer, } @@ -40,7 +41,7 @@ impl<'de, 'a, R: 'a + Read, B: BufferedXmlReader> de::EnumAccess<'de> for Enu } } -pub struct VariantAccess<'a, R: 'a + Read, B: BufferedXmlReader> { +pub struct VariantAccess<'a, R: Read, B: BufferedXmlReader> { de: &'a mut Deserializer, } diff --git a/src/error.rs b/src/error.rs index 8d6e4ad..5061b52 100644 --- a/src/error.rs +++ b/src/error.rs @@ -51,6 +51,7 @@ pub enum Error { pub type Result = std::result::Result; +#[macro_export] macro_rules! expect { ($actual: expr, $($expected: pat)|+ => $if_ok: expr) => { match $actual { @@ -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 { @@ -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 { diff --git a/src/lib.rs b/src/lib.rs index 1f93ed8..325c97d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; diff --git a/src/ser/mod.rs b/src/ser/mod.rs index bf97b1f..a29ca6f 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -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; @@ -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() { diff --git a/src/ser/var.rs b/src/ser/var.rs index 51b30c5..e4ee0f0 100644 --- a/src/ser/var.rs +++ b/src/ser/var.rs @@ -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, } @@ -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, name: &'w str, diff --git a/tests/failures.rs b/tests/failures.rs index 84fc36b..a0506c6 100644 --- a/tests/failures.rs +++ b/tests/failures.rs @@ -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(); diff --git a/tests/migrated.rs b/tests/migrated.rs index 8061fb4..39b97b2 100644 --- a/tests/migrated.rs +++ b/tests/migrated.rs @@ -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() { diff --git a/tests/readme.rs b/tests/readme.rs index 881d572..51ec7d7 100644 --- a/tests/readme.rs +++ b/tests/readme.rs @@ -1,4 +1,4 @@ -extern crate docmatic; +use docmatic; #[test] fn test_readme() { diff --git a/tests/round_trip.rs b/tests/round_trip.rs index 3e0f19f..4e0095a 100644 --- a/tests/round_trip.rs +++ b/tests/round_trip.rs @@ -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 { diff --git a/tests/test.rs b/tests/test.rs index ad103c4..52075b1 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -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;