Repository: ron-rs/ron
Pull request #149 (2019-03-03 08:23:03)

Transition to Rust 2018
Fix for #145


Patch:
diff --git a/Cargo.toml b/Cargo.toml
index e5e9e031..eefebbed 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,7 @@ authors = [
 	"Dzmitry Malyshau <kvarkus@gmail.com>",
 	"Thomas Schaller <torkleyy@gmail.com>",
 ]
+edition = "2018"
 description = "Rusty Object Notation"
 categories = ["encoding"]
 homepage = "https://github.com/ron-rs/ron"
diff --git a/examples/decode.rs b/examples/decode.rs
index c79ddc65..366f69b2 100644
--- a/examples/decode.rs
+++ b/examples/decode.rs
@@ -1,10 +1,6 @@
-extern crate ron;
-#[macro_use]
-extern crate serde;
-
-use std::collections::HashMap;
-
 use ron::de::from_str;
+use serde::Deserialize;
+use std::collections::HashMap;
 
 #[derive(Debug, Deserialize)]
 struct Config {
@@ -61,7 +57,7 @@ fn main() {
         Err(e) => {
             println!("Failed to load config: {}", e);
 
-            ::std::process::exit(1);
+            std::process::exit(1);
         }
     };
 
diff --git a/examples/decode_file.rs b/examples/decode_file.rs
index c4d00a68..cd88ffc5 100644
--- a/examples/decode_file.rs
+++ b/examples/decode_file.rs
@@ -1,11 +1,6 @@
-extern crate ron;
-#[macro_use]
-extern crate serde;
-
-use std::collections::HashMap;
-use std::fs::File;
-
 use ron::de::from_reader;
+use serde::Deserialize;
+use std::{collections::HashMap, fs::File};
 
 #[derive(Debug, Deserialize)]
 struct Config {
@@ -30,7 +25,7 @@ fn main() {
         Err(e) => {
             println!("Failed to load config: {}", e);
 
-            ::std::process::exit(1);
+            std::process::exit(1);
         }
     };
 
diff --git a/examples/encode.rs b/examples/encode.rs
index 389ac507..101208bb 100644
--- a/examples/encode.rs
+++ b/examples/encode.rs
@@ -1,11 +1,6 @@
-extern crate ron;
-#[macro_use]
-extern crate serde;
-
-use std::collections::HashMap;
-use std::default::Default;
-
 use ron::ser::{to_string_pretty, PrettyConfig};
+use serde::Serialize;
+use std::{collections::HashMap, iter::FromIterator};
 
 #[derive(Serialize)]
 struct Config {
@@ -32,8 +27,6 @@ struct Nested {
 }
 
 fn main() {
-    use std::iter::FromIterator;
-
     let data = Config {
         float: (2.18, -1.1),
         tuple: TupleStruct((), false),
diff --git a/examples/transcode.rs b/examples/transcode.rs
index 9577ec8e..401f6512 100644
--- a/examples/transcode.rs
+++ b/examples/transcode.rs
@@ -1,9 +1,5 @@
-extern crate ron;
-extern crate serde;
-extern crate serde_json;
-
 use ron::value::Value;
-use serde::ser::Serialize;
+use serde::Serialize;
 
 fn main() {
     let data = r#"
diff --git a/rustfmt.toml b/rustfmt.toml
index a20c3be1..c99aaef2 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,6 +1,5 @@
+merge_imports = true
 reorder_imports = true
-reorder_imported_names = true
-reorder_imports_in_group = true
 wrap_comments = false
 # This was unfortunately removed from rustfmt
 # re-enable once it (hopefully) gets added back
diff --git a/src/de/error.rs b/src/de/error.rs
index 5c6ed15d..f27f2029 100644
--- a/src/de/error.rs
+++ b/src/de/error.rs
@@ -1,17 +1,10 @@
-use std::error::Error as StdError;
-use std::fmt;
-use std::io;
-use std::str::Utf8Error;
-use std::string::FromUtf8Error;
-
-use base64;
-
 use serde::de;
+use std::{error::Error as StdError, fmt, io, str::Utf8Error, string::FromUtf8Error};
 
-use parse::Position;
+use crate::parse::Position;
 
 /// Deserialization result.
-pub type Result<T> = ::std::result::Result<T, Error>;
+pub type Result<T> = std::result::Result<T, Error>;
 
 #[derive(Clone, Debug, PartialEq)]
 pub enum Error {
@@ -58,11 +51,12 @@ pub enum ParseError {
     Utf8Error(Utf8Error),
     TrailingCharacters,
 
-    #[doc(hidden)] __NonExhaustive,
+    #[doc(hidden)]
+    __NonExhaustive,
 }
 
 impl fmt::Display for Error {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
             Error::IoError(ref s) => write!(f, "{}", s),
             Error::Message(ref s) => write!(f, "{}", s),
diff --git a/src/de/mod.rs b/src/de/mod.rs
index 930e6133..b67cd4d6 100644
--- a/src/de/mod.rs
+++ b/src/de/mod.rs
@@ -1,18 +1,13 @@
 /// Deserialization module.
 ///
 pub use self::error::{Error, ParseError, Result};
-pub use parse::Position;
+pub use crate::parse::Position;
 
-use std::borrow::Cow;
-use std::io;
-use std::str;
-
-use base64;
-
-use serde::de::{self, DeserializeSeed, Deserializer as Deserializer_, Visitor};
+use serde::de::{self, DeserializeSeed, Deserializer as _, Visitor};
+use std::{borrow::Cow, io, str};
 
 use self::id::IdDeserializer;
-use parse::{Bytes, Extensions};
+use crate::parse::{Bytes, Extensions, ParsedStr};
 
 mod error;
 mod id;
@@ -39,7 +34,7 @@ impl<'de> Deserializer<'de> {
         })
     }
 
-    pub fn remainder(&self) -> Cow<str> {
+    pub fn remainder(&self) -> Cow<'_, str> {
         String::from_utf8_lossy(&self.bytes.bytes())
     }
 }
@@ -99,10 +94,10 @@ impl<'de> Deserializer<'de> {
     /// This method assumes there is no identifier left.
     fn handle_any_struct<V>(&mut self, visitor: V) -> Result<V::Value>
     where
-        V: Visitor<'de>
+        V: Visitor<'de>,
     {
         // Create a working copy
-        let mut bytes = self.bytes.clone();
+        let mut bytes = self.bytes;
 
         match bytes.consume("(") {
             true => {
@@ -152,7 +147,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
             b'(' => self.handle_any_struct(visitor),
             b'[' => self.deserialize_seq(visitor),
             b'{' => self.deserialize_map(visitor),
-            b'0'...b'9' | b'+' | b'-' => {
+            b'0'..=b'9' | b'+' | b'-' => {
                 if self.bytes.next_bytes_is_float() {
                     self.deserialize_f64(visitor)
                 } else {
@@ -254,8 +249,6 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
     where
         V: Visitor<'de>,
     {
-        use parse::ParsedStr;
-
         match self.bytes.string()? {
             ParsedStr::Allocated(s) => visitor.visit_string(s),
             ParsedStr::Slice(s) => visitor.visit_str(s),
@@ -280,8 +273,6 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
     where
         V: Visitor<'de>,
     {
-        use parse::ParsedStr;
-
         let res = {
             let string = self.bytes.string()?;
             let base64_str = match string {
@@ -293,7 +284,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
 
         match res {
             Ok(byte_buf) => visitor.visit_byte_buf(byte_buf),
-            Err(err) => self.bytes.err(ParseError::Base64Error(err))
+            Err(err) => self.bytes.err(ParseError::Base64Error(err)),
         }
     }
 
@@ -303,29 +294,25 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
     {
         if self.bytes.consume("None") {
             visitor.visit_none()
-        } else {
-            if self.bytes.exts.contains(Extensions::IMPLICIT_SOME) {
-                visitor.visit_some(&mut *self)
-            } else {
-                if self.bytes.consume("Some") && {
-                    self.bytes.skip_ws()?;
-                    self.bytes.consume("(")
-                } {
-                    self.bytes.skip_ws()?;
+        } else if self.bytes.exts.contains(Extensions::IMPLICIT_SOME) {
+            visitor.visit_some(&mut *self)
+        } else if self.bytes.consume("Some") && {
+            self.bytes.skip_ws()?;
+            self.bytes.consume("(")
+        } {
+            self.bytes.skip_ws()?;
 
-                    let v = visitor.visit_some(&mut *self)?;
+            let v = visitor.visit_some(&mut *self)?;
 
-                    self.bytes.skip_ws()?;
+            self.bytes.skip_ws()?;
 
-                    if self.bytes.consume(")") {
-                        Ok(v)
-                    } else {
-                        self.bytes.err(ParseError::ExpectedOptionEnd)
-                    }
-                } else {
-                    self.bytes.err(ParseError::ExpectedOption)
-                }
+            if self.bytes.consume(")") {
+                Ok(v)
+            } else {
+                self.bytes.err(ParseError::ExpectedOptionEnd)
             }
+        } else {
+            self.bytes.err(ParseError::ExpectedOption)
         }
     }
 
@@ -490,8 +477,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
         V: Visitor<'de>,
     {
         visitor.visit_str(
-            str::from_utf8(self.bytes.identifier()?)
-                .map_err(|e| self.bytes.error(e.into()))?
+            str::from_utf8(self.bytes.identifier()?).map_err(|e| self.bytes.error(e.into()))?,
         )
     }
 
diff --git a/src/de/value.rs b/src/de/value.rs
index 2f06caa6..00b3596e 100644
--- a/src/de/value.rs
+++ b/src/de/value.rs
@@ -1,11 +1,14 @@
-use std::collections::BTreeMap;
-use std::fmt;
+use std::{collections::BTreeMap, fmt};
 
-use serde::{Deserialize, Deserializer};
-use serde::de::{Error, MapAccess, SeqAccess, Visitor};
+use serde::{
+    de::{Error, MapAccess, SeqAccess, Visitor},
+    Deserialize, Deserializer,
+};
 
-use de;
-use value::{Number, Value};
+use crate::{
+    de,
+    value::{Number, Value},
+};
 
 impl Value {
     /// Creates a value from a string reference.
@@ -33,7 +36,7 @@ struct ValueVisitor;
 impl<'de> Visitor<'de> for ValueVisitor {
     type Value = Value;
 
-    fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "a RON value")
     }
 
@@ -111,9 +114,9 @@ impl<'de> Visitor<'de> for ValueVisitor {
     where
         D: Deserializer<'de>,
     {
-        Ok(Value::Option(Some(
-            Box::new(deserializer.deserialize_any(ValueVisitor)?),
-        )))
+        Ok(Value::Option(Some(Box::new(
+            deserializer.deserialize_any(ValueVisitor)?,
+        ))))
     }
 
     fn visit_unit<E>(self) -> Result<Self::Value, E>
@@ -186,13 +189,11 @@ mod tests {
     fn test_tuples_basic() {
         assert_eq!(
             eval("(3, 4, 5)"),
-            Value::Seq(
-                vec![
-                    Value::Number(Number::new(3.0)),
-                    Value::Number(Number::new(4.0)),
-                    Value::Number(Number::new(5.0)),
-                ],
-            ),
+            Value::Seq(vec![
+                Value::Number(Number::new(3.0)),
+                Value::Number(Number::new(4.0)),
+                Value::Number(Number::new(5.0)),
+            ],),
         );
     }
 
@@ -200,20 +201,18 @@ mod tests {
     fn test_tuples_ident() {
         assert_eq!(
             eval("(true, 3, 4, 5)"),
-            Value::Seq(
-                vec![
-                    Value::Bool(true),
-                    Value::Number(Number::new(3.0)),
-                    Value::Number(Number::new(4.0)),
-                    Value::Number(Number::new(5.0)),
-                ],
-            ),
+            Value::Seq(vec![
+                Value::Bool(true),
+                Value::Number(Number::new(3.0)),
+                Value::Number(Number::new(4.0)),
+                Value::Number(Number::new(5.0)),
+            ]),
         );
     }
 
     #[test]
     fn test_tuples_error() {
-        use de::{Error, ParseError, Position};
+        use crate::de::{Error, ParseError, Position};
 
         assert_eq!(
             Value::from_str("Foo:").unwrap_err(),
@@ -255,8 +254,9 @@ mod tests {
                             Value::String("name".to_owned()),
                             Value::String("The Room".to_owned()),
                         ),
-                    ].into_iter()
-                        .collect(),
+                    ]
+                    .into_iter()
+                    .collect(),
                 ),
                 Value::Map(
                     vec![
@@ -288,12 +288,14 @@ mod tests {
                                         Value::String("Enemy3".to_owned()),
                                         Value::Number(Number::new(7.0)),
                                     ),
-                                ].into_iter()
-                                    .collect(),
+                                ]
+                                .into_iter()
+                                .collect(),
                             ),
                         ),
-                    ].into_iter()
-                        .collect(),
+                    ]
+                    .into_iter()
+                    .collect(),
                 ),
             ]))))
         );
diff --git a/src/lib.rs b/src/lib.rs
index 46bd9801..c6218017 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -57,18 +57,9 @@ Serializing / Deserializing is as simple as calling `to_string` / `from_str`.
 
 !*/
 
-#![deny(unused_must_use)]
-
-extern crate base64;
-
-#[macro_use]
-extern crate bitflags;
-#[macro_use]
-extern crate serde;
-
 pub mod de;
 pub mod ser;
 pub mod value;
-pub use value::Value;
+pub use crate::value::Value;
 
 mod parse;
diff --git a/src/parse.rs b/src/parse.rs
index 4eaf4a80..47743f3e 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -1,10 +1,13 @@
-use std::char::from_u32 as char_from_u32;
-use std::fmt::{Display, Formatter, Result as FmtResult};
-use std::ops::Neg;
-use std::result::Result as StdResult;
-use std::str::{FromStr, from_utf8, from_utf8_unchecked};
+use bitflags::bitflags;
+use std::{
+    char::from_u32 as char_from_u32,
+    fmt::{Display, Formatter, Result as FmtResult},
+    ops::Neg,
+    result::Result as StdResult,
+    str::{from_utf8, from_utf8_unchecked, FromStr},
+};
 
-use de::{Error, ParseError, Result};
+use crate::de::{Error, ParseError, Result};
 
 const DIGITS: &[u8] = b"0123456789ABCDEFabcdef_";
 const FLOAT_CHARS: &[u8] = b"0123456789.+-eE";
@@ -82,8 +85,6 @@ impl<'a> Bytes<'a> {
     }
 
     pub fn char(&mut self) -> Result<char> {
-        use std::cmp::min;
-
         if !self.consume("'") {
             return self.err(ParseError::ExpectedChar);
         }
@@ -98,7 +99,7 @@ impl<'a> Bytes<'a> {
             // Check where the end of the char (') is and try to
             // interpret the rest as UTF-8
 
-            let max = min(5, self.bytes.len());
+            let max = self.bytes.len().min(5);
             let pos: usize = self.bytes[..max]
                 .iter()
                 .position(|&x| x == b'\'')
@@ -146,8 +147,7 @@ impl<'a> Bytes<'a> {
     fn check_ident_char(&self, index: usize) -> bool {
         self.bytes
             .get(index)
-            .map(|b| IDENT_CHAR.contains(b))
-            .unwrap_or(false)
+            .map_or(false, |b| IDENT_CHAR.contains(b))
     }
 
     /// Should only be used on a working copy
@@ -196,9 +196,7 @@ impl<'a> Bytes<'a> {
                     Ok(false)
                 }
             })
-            .fold(Ok(true), |acc, x| {
-                acc.and_then(|val| x.map(|x| x && val))
-            })
+            .fold(Ok(true), |acc, x| acc.and_then(|val| x.map(|x| x && val)))
     }
 
     pub fn eat_byte(&mut self) -> Result<u8> {
@@ -303,7 +301,10 @@ impl<'a> Bytes<'a> {
             // If the next two bytes signify the start of a raw string literal,
             // return an error.
             if next == b'r' {
-                let second = self.bytes.get(1).ok_or(self.error(ParseError::Eof))?;
+                let second = self
+                    .bytes
+                    .get(1)
+                    .ok_or_else(|| self.error(ParseError::Eof))?;
                 if *second == b'"' || *second == b'#' {
                     return self.err(ParseError::ExpectedIdentifier);
                 }
@@ -321,7 +322,7 @@ impl<'a> Bytes<'a> {
         self.bytes
             .iter()
             .take_while(|b| allowed.contains(b))
-            .fold(0, |acc, _| acc + 1)
+            .count()
     }
 
     pub fn next_bytes_is_float(&self) -> bool {
@@ -330,16 +331,18 @@ impl<'a> Bytes<'a> {
                 b'+' | b'-' => 1,
                 _ => 0,
             };
-            let flen = self.bytes
-                        .iter()
-                        .skip(skip)
-                        .take_while(|b| FLOAT_CHARS.contains(b))
-                        .count();
-            let ilen = self.bytes
-                        .iter()
-                        .skip(skip)
-                        .take_while(|b| DIGITS.contains(b))
-                        .count();
+            let flen = self
+                .bytes
+                .iter()
+                .skip(skip)
+                .take_while(|b| FLOAT_CHARS.contains(b))
+                .count();
+            let ilen = self
+                .bytes
+                .iter()
+                .skip(skip)
+                .take_while(|b| DIGITS.contains(b))
+                .count();
             flen > ilen
         } else {
             false
@@ -347,10 +350,7 @@ impl<'a> Bytes<'a> {
     }
 
     pub fn skip_ws(&mut self) -> Result<()> {
-        while self.peek()
-            .map(|c| WHITE_SPACE.contains(&c))
-            .unwrap_or(false)
-        {
+        while self.peek().map_or(false, |c| WHITE_SPACE.contains(&c)) {
             let _ = self.advance_single();
         }
 
@@ -362,14 +362,14 @@ impl<'a> Bytes<'a> {
     }
 
     pub fn peek(&self) -> Option<u8> {
-        self.bytes.get(0).map(|b| *b)
+        self.bytes.get(0).cloned()
     }
 
     pub fn peek_or_eof(&self) -> Result<u8> {
         self.bytes
             .get(0)
-            .map(|b| *b)
-            .ok_or(self.error(ParseError::Eof))
+            .cloned()
+            .ok_or_else(|| self.error(ParseError::Eof))
     }
 
     pub fn signed_integer<T>(&mut self) -> Result<T>
@@ -391,7 +391,7 @@ impl<'a> Bytes<'a> {
         }
     }
 
-    pub fn string(&mut self) -> Result<ParsedStr> {
+    pub fn string(&mut self) -> Result<ParsedStr<'_>> {
         if self.consume("\"") {
             self.escaped_string()
         } else if self.consume("r") {
@@ -401,14 +401,15 @@ impl<'a> Bytes<'a> {
         }
     }
 
-    fn escaped_string(&mut self) -> Result<ParsedStr> {
+    fn escaped_string(&mut self) -> Result<ParsedStr<'_>> {
         use std::iter::repeat;
 
-        let (i, end_or_escape) = self.bytes
+        let (i, end_or_escape) = self
+            .bytes
             .iter()
             .enumerate()
             .find(|&(_, &b)| b == b'\\' || b == b'"')
-            .ok_or(self.error(ParseError::ExpectedStringEnd))?;
+            .ok_or_else(|| self.error(ParseError::ExpectedStringEnd))?;
 
         if *end_or_escape == b'"' {
             let s = from_utf8(&self.bytes[..i]).map_err(|e| self.error(e.into()))?;
@@ -434,7 +435,8 @@ impl<'a> Bytes<'a> {
                     }
                 }
 
-                let (new_i, end_or_escape) = self.bytes
+                let (new_i, end_or_escape) = self
+                    .bytes
                     .iter()
                     .enumerate()
                     .find(|&(_, &b)| b == b'\\' || b == b'"')
@@ -454,7 +456,7 @@ impl<'a> Bytes<'a> {
         }
     }
 
-    fn raw_string(&mut self) -> Result<ParsedStr> {
+    fn raw_string(&mut self) -> Result<ParsedStr<'_>> {
         let num_hashes = self.bytes.iter().take_while(|&&b| b == b'#').count();
         let hashes = &self.bytes[..num_hashes];
         let _ = self.advance(num_hashes);
@@ -464,10 +466,11 @@ impl<'a> Bytes<'a> {
         }
 
         let ending = [&[b'"'], hashes].concat();
-        let i = self.bytes
+        let i = self
+            .bytes
             .windows(num_hashes + 1)
             .position(|window| window == ending.as_slice())
-            .ok_or(self.error(ParseError::ExpectedStringEnd))?;
+            .ok_or_else(|| self.error(ParseError::ExpectedStringEnd))?;
 
         let s = from_utf8(&self.bytes[..i]).map_err(|e| self.error(e.into()))?;
 
@@ -481,7 +484,7 @@ impl<'a> Bytes<'a> {
     fn test_for(&self, s: &str) -> bool {
         s.bytes()
             .enumerate()
-            .all(|(i, b)| self.bytes.get(i).map(|t| *t == b).unwrap_or(false))
+            .all(|(i, b)| self.bytes.get(i).map_or(false, |t| *t == b))
     }
 
     pub fn unsigned_integer<T: Num>(&mut self) -> Result<T> {
@@ -520,10 +523,7 @@ impl<'a> Bytes<'a> {
             s = &tmp;
         }
 
-        let res = Num::from_str(
-            s,
-            base,
-        ).map_err(|_| self.error(ParseError::ExpectedInteger));
+        let res = Num::from_str(s, base).map_err(|_| self.error(ParseError::ExpectedInteger));
 
         let _ = self.advance(num_bytes);
 
@@ -533,7 +533,7 @@ impl<'a> Bytes<'a> {
     fn decode_ascii_escape(&mut self) -> Result<u8> {
         let mut n = 0;
         for _ in 0..2 {
-            n = n << 4;
+            n <<= 4;
             let byte = self.eat_byte()?;
             let decoded = self.decode_hex(byte)?;
             n |= decoded;
@@ -544,9 +544,9 @@ impl<'a> Bytes<'a> {
 
     fn decode_hex(&self, c: u8) -> Result<u8> {
         match c {
-            c @ b'0'...b'9' => Ok(c - b'0'),
-            c @ b'a'...b'f' => Ok(10 + c - b'a'),
-            c @ b'A'...b'F' => Ok(10 + c - b'A'),
+            c @ b'0'..=b'9' => Ok(c - b'0'),
+            c @ b'a'..=b'f' => Ok(10 + c - b'a'),
+            c @ b'A'..=b'F' => Ok(10 + c - b'A'),
             _ => self.err(ParseError::InvalidEscape("Non-hex digit found")),
         }
     }
@@ -576,7 +576,7 @@ impl<'a> Bytes<'a> {
                     }
 
                     let byte = self.decode_hex(byte)?;
-                    bytes = bytes << 4;
+                    bytes <<= 4;
                     bytes |= byte as u32;
 
                     num_digits += 1;
@@ -613,12 +613,13 @@ impl<'a> Bytes<'a> {
                     let mut level = 1;
 
                     while level > 0 {
-                        let bytes = self.bytes
+                        let bytes = self
+                            .bytes
                             .iter()
                             .take_while(|&&b| b != b'/' && b != b'*')
                             .count();
 
-                        if self.bytes.len() == 0 {
+                        if self.bytes.is_empty() {
                             return self.err(ParseError::UnclosedBlockComment);
                         }
 
@@ -695,7 +696,7 @@ pub struct Position {
 }
 
 impl Display for Position {
-    fn fmt(&self, f: &mut Formatter) -> FmtResult {
+    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
         write!(f, "{}:{}", self.line, self.col)
     }
 }
diff --git a/src/ser/mod.rs b/src/ser/mod.rs
index 6f4c7a38..855c5e8d 100644
--- a/src/ser/mod.rs
+++ b/src/ser/mod.rs
@@ -1,10 +1,8 @@
-use std::error::Error as StdError;
-use std::fmt::{Display, Formatter, Write, Result as FmtResult};
-use std::result::Result as StdResult;
-
-use base64;
-
-use serde::ser::{self, Serialize};
+use serde::{ser, Deserialize, Serialize};
+use std::{
+    error::Error as StdError,
+    fmt::{Display, Formatter, Result as FmtResult, Write},
+};
 
 mod value;
 
@@ -32,7 +30,13 @@ where
 {
     let mut s = Serializer {
         output: String::new(),
-        pretty: Some((config, Pretty { indent: 0, sequence_index: Vec::new() })),
+        pretty: Some((
+            config,
+            Pretty {
+                indent: 0,
+                sequence_index: Vec::new(),
+            },
+        )),
         struct_names: false,
     };
     value.serialize(&mut s)?;
@@ -40,7 +44,7 @@ where
 }
 
 /// Serialization result.
-pub type Result<T> = StdResult<T, Error>;
+pub type Result<T> = std::result::Result<T, Error>;
 
 /// Serialization error.
 #[derive(Clone, Debug, PartialEq)]
@@ -50,7 +54,7 @@ pub enum Error {
 }
 
 impl Display for Error {
-    fn fmt(&self, f: &mut Formatter) -> FmtResult {
+    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
         match *self {
             Error::Message(ref e) => write!(f, "Custom message: {}", e),
         }
@@ -124,7 +128,15 @@ impl Serializer {
     pub fn new(config: Option<PrettyConfig>, struct_names: bool) -> Self {
         Serializer {
             output: String::new(),
-            pretty: config.map(|conf| (conf, Pretty { indent: 0, sequence_index: Vec::new() })),
+            pretty: config.map(|conf| {
+                (
+                    conf,
+                    Pretty {
+                        indent: 0,
+                        sequence_index: Vec::new(),
+                    },
+                )
+            }),
             struct_names,
         }
     }
@@ -144,8 +156,7 @@ impl Serializer {
     fn separate_tuple_members(&self) -> bool {
         self.pretty
             .as_ref()
-            .map(|&(ref config, _)| config.separate_tuple_members)
-            .unwrap_or(false)
+            .map_or(false, |&(ref config, _)| config.separate_tuple_members)
     }
 
     fn start_indent(&mut self) {
@@ -177,8 +188,9 @@ impl Serializer {
     }
 
     fn serialize_escaped_str(&mut self, value: &str) {
+        let value = value.chars().flat_map(|c| c.escape_debug());
         self.output += "\"";
-        self.output.extend(value.chars().flat_map(|c| c.escape_debug()));
+        self.output.extend(value);
         self.output += "\"";
     }
 }
@@ -740,10 +752,13 @@ mod tests {
 
     #[test]
     fn test_byte_stream() {
-        extern crate serde_bytes;
+        use serde_bytes;
 
         let small: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
-        assert_eq!(to_string(&small).unwrap(), "(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,)");
+        assert_eq!(
+            to_string(&small).unwrap(),
+            "(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,)"
+        );
 
         let large = vec![255u8; 64];
         let large = serde_bytes::Bytes::new(&large);
diff --git a/src/ser/value.rs b/src/ser/value.rs
index 52633378..d3109ec3 100644
--- a/src/ser/value.rs
+++ b/src/ser/value.rs
@@ -1,6 +1,6 @@
 use serde::ser::{Serialize, Serializer};
 
-use value::Value;
+use crate::value::Value;
 
 impl Serialize for Value {
     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
diff --git a/src/value.rs b/src/value.rs
index f53e494a..52d1ba4f 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -1,12 +1,18 @@
 //! Value module.
 
-use std::cmp::{Eq, Ordering};
-use std::collections::BTreeMap;
-use std::hash::{Hash, Hasher};
-
-use serde::de::{DeserializeOwned, DeserializeSeed, Deserializer, Error as SerdeErr, MapAccess, SeqAccess, Visitor};
-
-use de::{Error as RonError, Result};
+use serde::{
+    de::{
+        DeserializeOwned, DeserializeSeed, Deserializer, Error as _, MapAccess, SeqAccess, Visitor,
+    },
+    forward_to_deserialize_any,
+};
+use std::{
+    cmp::{Eq, Ordering},
+    collections::BTreeMap,
+    hash::{Hash, Hasher},
+};
+
+use crate::de::{Error as RonError, Result};
 
 /// A wrapper for `f64` which guarantees that the inner value
 /// is finite and thus implements `Eq`, `Hash` and `Ord`.
@@ -25,7 +31,7 @@ impl Number {
     }
 
     /// Returns the wrapped float.
-    pub fn get(&self) -> f64 {
+    pub fn get(self) -> f64 {
         self.0
     }
 }
@@ -88,7 +94,6 @@ impl<'de> Deserializer<'de> for Value {
             Value::String(s) => visitor.visit_string(s),
             Value::Seq(mut seq) => {
                 seq.reverse();
-
                 visitor.visit_seq(Seq { seq })
             }
             Value::Unit => visitor.visit_unit(),
@@ -222,7 +227,7 @@ mod tests {
     where
         T: Debug + Deserialize<'de> + PartialEq,
     {
-        use de::from_str;
+        use crate::de::from_str;
 
         let direct: T = from_str(s).unwrap();
         let value: Value = from_str(s).unwrap();


Test patch:
diff --git a/src/de/tests.rs b/src/de/tests.rs
index 45592fd9..04be82d3 100644
--- a/src/de/tests.rs
+++ b/src/de/tests.rs
@@ -1,4 +1,5 @@
-extern crate serde_bytes;
+use serde::Deserialize;
+use serde_bytes;
 
 use super::*;
 
@@ -22,7 +23,6 @@ enum MyEnum {
     D { a: i32, b: i32 },
 }
 
-
 #[derive(Debug, Deserialize, PartialEq)]
 struct BytesStruct {
     small: Vec<u8>,
@@ -144,12 +144,13 @@ x: 1.0, // x is just 1
 // And y is indeed
 y: 2.0 // 2!
     )"
-        ).unwrap()
+        )
+        .unwrap()
     );
 }
 
 fn err<T>(kind: ParseError, line: usize, col: usize) -> Result<T> {
-    use parse::Position;
+    use crate::parse::Position;
 
     Err(Error::Parser(kind, Position { line, col }))
 }
@@ -289,7 +290,10 @@ fn ws_tuple_newtype_variant() {
 #[test]
 fn test_byte_stream() {
     assert_eq!(
-        Ok(BytesStruct{ small: vec![1, 2], large: vec![1, 2, 3, 4] }),
+        Ok(BytesStruct {
+            small: vec![1, 2],
+            large: vec![1, 2, 3, 4]
+        }),
         from_str("BytesStruct( small:[1, 2], large:\"AQIDBA==\" )"),
     );
 }
diff --git a/tests/big_struct.rs b/tests/big_struct.rs
index bd512194..40583606 100644
--- a/tests/big_struct.rs
+++ b/tests/big_struct.rs
@@ -1,6 +1,4 @@
-extern crate ron;
-#[macro_use]
-extern crate serde;
+use serde::{Deserialize, Serialize};
 
 #[derive(Serialize, Deserialize)]
 pub struct ImVec2 {
diff --git a/tests/comments.rs b/tests/comments.rs
index 25662156..d49ef73c 100644
--- a/tests/comments.rs
+++ b/tests/comments.rs
@@ -1,21 +1,23 @@
-extern crate ron;
-
-use ron::de::Error as RonErr;
-use ron::de::ParseError;
-use ron::de::Position;
+use ron::de::{from_str, Error as RonErr, ParseError, Position};
 
 #[test]
 fn test_simple() {
-    assert_eq!(ron::de::from_str("/*
+    assert_eq!(
+        from_str(
+            "/*
  * We got a hexadecimal number here!
  *
  */0x507"
-    ), Ok(0x507));
+        ),
+        Ok(0x507)
+    );
 }
 
 #[test]
 fn test_nested() {
-    assert_eq!(ron::de::from_str("/*
+    assert_eq!(
+        from_str(
+            "/*
         /* quite * some * nesting * going * on * /* here /* (yeah, maybe a bit too much) */ */ */
     */
     // The actual value comes.. /*
@@ -23,12 +25,16 @@ fn test_nested() {
     // multi-line comments don't trigger in line comments /*
 \"THE VALUE\" /* This is the value /* :) */ */
     "
-    ), Ok("THE VALUE".to_owned()));
+        ),
+        Ok("THE VALUE".to_owned())
+    );
 }
 
 #[test]
 fn test_unclosed() {
-    assert_eq!(ron::de::from_str::<String>("/*
+    assert_eq!(
+        from_str::<String>(
+            "/*
         /* quite * some * nesting * going * on * /* here /* (yeah, maybe a bit too much) */ */ */
     */
     // The actual value comes.. /*
@@ -37,5 +43,10 @@ fn test_unclosed() {
 /* Unfortunately, this comment won't get closed :(
 \"THE VALUE (which is invalid)\"
 "
-    ), Err(RonErr::Parser(ParseError::UnclosedBlockComment, Position { col: 1, line: 9 })));
+        ),
+        Err(RonErr::Parser(
+            ParseError::UnclosedBlockComment,
+            Position { col: 1, line: 9 }
+        ))
+    );
 }
diff --git a/tests/depth_limit.rs b/tests/depth_limit.rs
index 767b3f51..beacc02e 100644
--- a/tests/depth_limit.rs
+++ b/tests/depth_limit.rs
@@ -1,7 +1,4 @@
-extern crate ron;
-#[macro_use]
-extern crate serde;
-
+use serde::Serialize;
 use std::collections::HashMap;
 
 #[derive(Serialize)]
diff --git a/tests/escape.rs b/tests/escape.rs
index d0046ccc..20cc87ee 100644
--- a/tests/escape.rs
+++ b/tests/escape.rs
@@ -1,12 +1,6 @@
-extern crate ron;
-extern crate serde;
-
-use std::char::from_u32;
-use std::fmt::Debug;
-
-use ron::de::from_str;
-use ron::ser::to_string;
+use ron::{de::from_str, ser::to_string};
 use serde::{Deserialize, Serialize};
+use std::{char::from_u32, fmt::Debug};
 
 #[test]
 fn test_escape_basic() {
diff --git a/tests/extensions.rs b/tests/extensions.rs
index 18f31cc0..81157257 100644
--- a/tests/extensions.rs
+++ b/tests/extensions.rs
@@ -1,7 +1,4 @@
-extern crate ron;
-#[macro_use]
-extern crate serde;
-
+use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
 
 #[derive(Debug, PartialEq, Deserialize, Serialize)]
diff --git a/tests/numbers.rs b/tests/numbers.rs
index b19ae913..26b97a53 100644
--- a/tests/numbers.rs
+++ b/tests/numbers.rs
@@ -1,22 +1,22 @@
-extern crate ron;
+use ron::de::from_str;
 
 #[test]
 fn test_hex() {
-    assert_eq!(ron::de::from_str("0x507"), Ok(0x507));
-    assert_eq!(ron::de::from_str("0x1A5"), Ok(0x1A5));
-    assert_eq!(ron::de::from_str("0x53C537"), Ok(0x53C537));
+    assert_eq!(from_str("0x507"), Ok(0x507));
+    assert_eq!(from_str("0x1A5"), Ok(0x1A5));
+    assert_eq!(from_str("0x53C537"), Ok(0x53C537));
 }
 
 #[test]
 fn test_bin() {
-    assert_eq!(ron::de::from_str("0b101"), Ok(0b101));
-    assert_eq!(ron::de::from_str("0b001"), Ok(0b001));
-    assert_eq!(ron::de::from_str("0b100100"), Ok(0b100100));
+    assert_eq!(from_str("0b101"), Ok(0b101));
+    assert_eq!(from_str("0b001"), Ok(0b001));
+    assert_eq!(from_str("0b100100"), Ok(0b100100));
 }
 
 #[test]
 fn test_oct() {
-    assert_eq!(ron::de::from_str("0o1461"), Ok(0o1461));
-    assert_eq!(ron::de::from_str("0o051"), Ok(0o051));
-    assert_eq!(ron::de::from_str("0o150700"), Ok(0o150700));
+    assert_eq!(from_str("0o1461"), Ok(0o1461));
+    assert_eq!(from_str("0o051"), Ok(0o051));
+    assert_eq!(from_str("0o150700"), Ok(0o150700));
 }
diff --git a/tests/roundtrip.rs b/tests/roundtrip.rs
index e990c55c..de12a5b2 100644
--- a/tests/roundtrip.rs
+++ b/tests/roundtrip.rs
@@ -1,7 +1,4 @@
-extern crate ron;
-#[macro_use]
-extern crate serde;
-
+use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
 
 #[derive(Debug, PartialEq, Deserialize, Serialize)]
@@ -40,8 +37,9 @@ fn roundtrip() {
             (Key(6), Enum::Bool(false)),
             (Key(7), Enum::Bool(true)),
             (Key(9), Enum::Chars('x', "".to_string())),
-        ].into_iter()
-            .collect(),
+        ]
+        .into_iter()
+        .collect(),
     };
 
     let serial = ron::ser::to_string(&value).unwrap();
@@ -63,8 +61,9 @@ fn roundtrip_pretty() {
             (Key(6), Enum::Bool(false)),
             (Key(7), Enum::Bool(true)),
             (Key(9), Enum::Chars('x', "".to_string())),
-        ].into_iter()
-            .collect(),
+        ]
+        .into_iter()
+        .collect(),
     };
 
     let pretty = ron::ser::PrettyConfig {
@@ -102,15 +101,13 @@ fn roundtrip_sep_tuple_members() {
             (Key(6), Enum::Bool(false)),
             (Key(7), Enum::Bool(true)),
             (Key(9), Enum::Chars('x', "".to_string())),
-        ].into_iter()
-            .collect(),
+        ]
+        .into_iter()
+        .collect(),
     };
     let b = FileOrMem::File("foo".to_owned());
 
-    let value = Both {
-        a,
-        b,
-    };
+    let value = Both { a, b };
 
     let pretty = ron::ser::PrettyConfig {
         depth_limit: !0,
diff --git a/tests/unicode.rs b/tests/unicode.rs
index 43316dde..0617eeed 100644
--- a/tests/unicode.rs
+++ b/tests/unicode.rs
@@ -1,5 +1,3 @@
-extern crate ron;
-
 use ron::de::from_str;
 
 #[test]
diff --git a/tests/value.rs b/tests/value.rs
index a537b0b1..6787dcbb 100644
--- a/tests/value.rs
+++ b/tests/value.rs
@@ -1,10 +1,6 @@
-extern crate ron;
-#[macro_use]
-extern crate serde;
-
-use std::collections::BTreeMap;
-
 use ron::value::{Number, Value};
+use serde::Serialize;
+use std::collections::BTreeMap;
 
 #[test]
 fn bool() {
@@ -28,7 +24,10 @@ fn map() {
 #[test]
 fn number() {
     assert_eq!(Value::from_str("42"), Ok(Value::Number(Number::new(42f64))));
-    assert_eq!(Value::from_str("3.1415"), Ok(Value::Number(Number::new(3.1415f64))));
+    assert_eq!(
+        Value::from_str("3.1415"),
+        Ok(Value::Number(Number::new(3.1415f64)))
+    );
 }
 
 #[test]
@@ -46,18 +45,30 @@ fn string() {
     assert_eq!(Value::from_str(raw), Ok(Value::String("Raw String".into())));
 
     let raw_hashes = "r#\"Raw String\"#";
-    assert_eq!(Value::from_str(raw_hashes), Ok(Value::String("Raw String".into())));
+    assert_eq!(
+        Value::from_str(raw_hashes),
+        Ok(Value::String("Raw String".into()))
+    );
 
     let raw_escaped = "r##\"Contains \"#\"##";
-    assert_eq!(Value::from_str(raw_escaped), Ok(Value::String("Contains \"#".into())));
+    assert_eq!(
+        Value::from_str(raw_escaped),
+        Ok(Value::String("Contains \"#".into()))
+    );
 
     let raw_multi_line = "r\"Multi\nLine\"";
-    assert_eq!(Value::from_str(raw_multi_line), Ok(Value::String("Multi\nLine".into())));
+    assert_eq!(
+        Value::from_str(raw_multi_line),
+        Ok(Value::String("Multi\nLine".into()))
+    );
 }
 
 #[test]
 fn seq() {
-    let seq = vec![Value::Number(Number::new(1f64)), Value::Number(Number::new(2f64))];
+    let seq = vec![
+        Value::Number(Number::new(1f64)),
+        Value::Number(Number::new(2f64)),
+    ];
     assert_eq!(Value::from_str("[1, 2]"), Ok(Value::Seq(seq)));
 }
 
@@ -68,10 +79,10 @@ fn unit() {
     assert_eq!(Value::from_str("()"), Ok(Value::Unit));
     assert_eq!(Value::from_str("Foo"), Ok(Value::Unit));
 
-    assert_eq!(Value::from_str(""), Err(Error::Parser(
-        ParseError::Eof,
-        Position { col: 1, line: 1 }
-    )));
+    assert_eq!(
+        Value::from_str(""),
+        Err(Error::Parser(ParseError::Eof, Position { col: 1, line: 1 }))
+    );
 }
 
 #[derive(Serialize)]
@@ -84,17 +95,19 @@ struct Scene2 {
 
 #[test]
 fn roundtrip() {
-    use ron::ser::to_string;
-    use ron::de::from_str;
+    use ron::{de::from_str, ser::to_string};
 
     {
-        let s = to_string(&Scene2 { foo: Some((122, 13)) }).unwrap();
+        let s = to_string(&Scene2 {
+            foo: Some((122, 13)),
+        })
+        .unwrap();
         println!("{}", s);
         let scene: Value = from_str(&s).unwrap();
         println!("{:?}", scene);
     }
     {
-        let s = to_string(&Scene( Some((13, 122)) )).unwrap();
+        let s = to_string(&Scene(Some((13, 122)))).unwrap();
         println!("{}", s);
         let scene: Value = from_str(&s).unwrap();
         println!("{:?}", scene);