aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Huss <eric@huss.org>2019-05-08 17:37:38 -0700
committerEric Huss <eric@huss.org>2019-05-08 17:37:38 -0700
commit6c162e6562c3e432bf04c82a3d1d789d80761a86 (patch)
tree5b8b428c5408cb138f5a3674ad33ba8dcb71b460 /src
parent1b016589133e48d34dd5ae1b440581ded4cb4cdb (diff)
downloadmilf-rs-6c162e6562c3e432bf04c82a3d1d789d80761a86.tar.gz
milf-rs-6c162e6562c3e432bf04c82a3d1d789d80761a86.zip
2018 edition idioms.
Diffstat (limited to 'src')
-rw-r--r--src/datetime.rs22
-rw-r--r--src/de.rs18
-rw-r--r--src/lib.rs14
-rw-r--r--src/macros.rs5
-rw-r--r--src/map.rs14
-rw-r--r--src/ser.rs24
-rw-r--r--src/spanned.rs7
-rw-r--r--src/tokens.rs10
-rw-r--r--src/value.rs8
9 files changed, 51 insertions, 71 deletions
diff --git a/src/datetime.rs b/src/datetime.rs
index b77621a..61eb3b1 100644
--- a/src/datetime.rs
+++ b/src/datetime.rs
@@ -65,13 +65,13 @@ enum Offset {
}
impl fmt::Debug for Datetime {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl fmt::Display for Datetime {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(ref date) = self.date {
write!(f, "{}", date)?;
}
@@ -89,13 +89,13 @@ impl fmt::Display for Datetime {
}
impl fmt::Display for Date {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04}-{:02}-{:02}", self.year, self.month, self.day)
}
}
impl fmt::Display for Time {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:02}:{:02}:{:02}", self.hour, self.minute, self.second)?;
if self.nanosecond != 0 {
let s = format!("{:09}", self.nanosecond);
@@ -106,7 +106,7 @@ impl fmt::Display for Time {
}
impl fmt::Display for Offset {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Offset::Z => write!(f, "Z"),
Offset::Custom { hours, minutes } => write!(f, "{:+03}:{:02}", hours, minutes),
@@ -207,7 +207,7 @@ impl FromStr for Datetime {
let mut end = whole.len();
for (i, byte) in whole.bytes().enumerate() {
match byte {
- b'0'...b'9' => {
+ b'0'..=b'9' => {
if i < 9 {
let p = 10_u32.pow(8 - i as u32);
nanosecond += p * (byte - b'0') as u32;
@@ -298,7 +298,7 @@ impl FromStr for Datetime {
}
}
-fn digit(chars: &mut str::Chars) -> Result<u8, DatetimeParseError> {
+fn digit(chars: &mut str::Chars<'_>) -> Result<u8, DatetimeParseError> {
match chars.next() {
Some(c) if '0' <= c && c <= '9' => Ok(c as u8 - b'0'),
_ => Err(DatetimeParseError { _private: () }),
@@ -328,7 +328,7 @@ impl<'de> de::Deserialize<'de> for Datetime {
impl<'de> de::Visitor<'de> for DatetimeVisitor {
type Value = Datetime;
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a TOML datetime")
}
@@ -362,7 +362,7 @@ impl<'de> de::Deserialize<'de> for DatetimeKey {
impl<'de> de::Visitor<'de> for FieldVisitor {
type Value = ();
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a valid datetime field")
}
@@ -397,7 +397,7 @@ impl<'de> de::Deserialize<'de> for DatetimeFromString {
impl<'de> de::Visitor<'de> for Visitor {
type Value = DatetimeFromString;
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("string containing a datetime")
}
@@ -417,7 +417,7 @@ impl<'de> de::Deserialize<'de> for DatetimeFromString {
}
impl fmt::Display for DatetimeParseError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"failed to parse datetime".fmt(f)
}
}
diff --git a/src/de.rs b/src/de.rs
index 291da3b..077c008 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -41,9 +41,7 @@ where
/// # Examples
///
/// ```
-/// #[macro_use]
-/// extern crate serde_derive;
-/// extern crate toml;
+/// use serde_derive::Deserialize;
///
/// #[derive(Deserialize)]
/// struct Config {
@@ -265,7 +263,7 @@ impl<'de, 'b> de::Deserializer<'de> for &'b mut Deserializer<'de> {
}
}
- forward_to_deserialize_any! {
+ serde::forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
bytes byte_buf map struct unit newtype_struct
ignored_any unit_struct tuple_struct tuple option identifier
@@ -495,7 +493,7 @@ impl<'de, 'b> de::Deserializer<'de> for MapVisitor<'de, 'b> {
visitor.visit_newtype_struct(self)
}
- forward_to_deserialize_any! {
+ serde::forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
bytes byte_buf map struct unit identifier
ignored_any unit_struct tuple_struct tuple enum
@@ -525,7 +523,7 @@ impl<'de> de::Deserializer<'de> for StrDeserializer<'de> {
}
}
- forward_to_deserialize_any! {
+ serde::forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
bytes byte_buf map struct option unit newtype_struct
ignored_any unit_struct tuple_struct tuple enum identifier
@@ -699,7 +697,7 @@ impl<'de> de::Deserializer<'de> for ValueDeserializer<'de> {
visitor.visit_newtype_struct(self)
}
- forward_to_deserialize_any! {
+ serde::forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
bytes byte_buf map unit identifier
ignored_any unit_struct tuple_struct tuple
@@ -796,7 +794,7 @@ impl<'de> de::Deserializer<'de> for DatetimeFieldDeserializer {
visitor.visit_borrowed_str(datetime::FIELD)
}
- forward_to_deserialize_any! {
+ serde::forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
bytes byte_buf map struct option unit newtype_struct
ignored_any unit_struct tuple_struct tuple enum identifier
@@ -1520,7 +1518,7 @@ impl<'a> Deserializer<'a> {
fn array(&mut self) -> Result<(Span, Vec<Value<'a>>), Error> {
let mut ret = Vec::new();
- let intermediate = |me: &mut Deserializer| {
+ let intermediate = |me: &mut Deserializer<'_>| {
loop {
me.eat_whitespace()?;
if !me.eat(Token::Newline)? && !me.eat_comment()? {
@@ -1775,7 +1773,7 @@ impl Error {
}
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.inner.kind {
ErrorKind::UnexpectedEof => "unexpected eof encountered".fmt(f)?,
ErrorKind::InvalidCharInString(c) => write!(
diff --git a/src/lib.rs b/src/lib.rs
index 7e8dbbe..30ee3bc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -77,9 +77,7 @@
//! An example of deserializing with TOML is:
//!
//! ```rust
-//! #[macro_use]
-//! extern crate serde_derive;
-//! extern crate toml;
+//! use serde_derive::Deserialize;
//!
//! #[derive(Deserialize)]
//! struct Config {
@@ -113,9 +111,7 @@
//! You can serialize types in a similar fashion:
//!
//! ```rust
-//! #[macro_use]
-//! extern crate serde_derive;
-//! extern crate toml;
+//! use serde_derive::Serialize;
//!
//! #[derive(Serialize)]
//! struct Config {
@@ -150,11 +146,7 @@
#![doc(html_root_url = "https://docs.rs/toml/0.5")]
#![deny(missing_docs)]
-
-#[macro_use]
-extern crate serde;
-#[cfg(feature = "preserve_order")]
-extern crate linked_hash_map;
+#![warn(rust_2018_idioms)]
pub mod map;
pub mod value;
diff --git a/src/macros.rs b/src/macros.rs
index 9f11733..0731afe 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -7,11 +7,8 @@ use crate::value::{Array, Table, Value};
/// [`toml::Value`]: value/enum.Value.html
///
/// ```rust
-/// #[macro_use]
-/// extern crate toml;
-///
/// fn main() {
-/// let cargo_toml = toml! {
+/// let cargo_toml = toml::toml! {
/// [package]
/// name = "toml"
/// version = "0.4.5"
diff --git a/src/map.rs b/src/map.rs
index 3a2473a..054961d 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -140,7 +140,7 @@ impl Map<String, Value> {
/// Gets the given key's corresponding entry in the map for in-place
/// manipulation.
- pub fn entry<S>(&mut self, key: S) -> Entry
+ pub fn entry<S>(&mut self, key: S) -> Entry<'_>
where
S: Into<String>,
{
@@ -169,7 +169,7 @@ impl Map<String, Value> {
/// Gets an iterator over the entries of the map.
#[inline]
- pub fn iter(&self) -> Iter {
+ pub fn iter(&self) -> Iter<'_> {
Iter {
iter: self.map.iter(),
}
@@ -177,7 +177,7 @@ impl Map<String, Value> {
/// Gets a mutable iterator over the entries of the map.
#[inline]
- pub fn iter_mut(&mut self) -> IterMut {
+ pub fn iter_mut(&mut self) -> IterMut<'_> {
IterMut {
iter: self.map.iter_mut(),
}
@@ -185,7 +185,7 @@ impl Map<String, Value> {
/// Gets an iterator over the keys of the map.
#[inline]
- pub fn keys(&self) -> Keys {
+ pub fn keys(&self) -> Keys<'_> {
Keys {
iter: self.map.keys(),
}
@@ -193,7 +193,7 @@ impl Map<String, Value> {
/// Gets an iterator over the values of the map.
#[inline]
- pub fn values(&self) -> Values {
+ pub fn values(&self) -> Values<'_> {
Values {
iter: self.map.values(),
}
@@ -253,7 +253,7 @@ where
impl Debug for Map<String, Value> {
#[inline]
- fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
self.map.fmt(formatter)
}
}
@@ -285,7 +285,7 @@ impl<'de> de::Deserialize<'de> for Map<String, Value> {
impl<'de> de::Visitor<'de> for Visitor {
type Value = Map<String, Value>;
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a map")
}
diff --git a/src/ser.rs b/src/ser.rs
index 2dcd962..328772a 100644
--- a/src/ser.rs
+++ b/src/ser.rs
@@ -12,8 +12,7 @@
//! may use the `tables_last` function in this module like so:
//!
//! ```rust
-//! # #[macro_use] extern crate serde_derive;
-//! # extern crate toml;
+//! # use serde_derive::Serialize;
//! # use std::collections::HashMap;
//! #[derive(Serialize)]
//! struct Manifest {
@@ -56,9 +55,7 @@ where
/// # Examples
///
/// ```
-/// #[macro_use]
-/// extern crate serde_derive;
-/// extern crate toml;
+/// use serde_derive::Serialize;
///
/// #[derive(Serialize)]
/// struct Config {
@@ -442,7 +439,7 @@ impl<'a> Serializer<'a> {
}
// recursive implementation of `emit_key` above
- fn _emit_key(&mut self, state: &State) -> Result<(), Error> {
+ fn _emit_key(&mut self, state: &State<'_>) -> Result<(), Error> {
match *state {
State::End => Ok(()),
State::Array {
@@ -479,7 +476,7 @@ impl<'a> Serializer<'a> {
fn emit_array(&mut self, first: &Cell<bool>, len: Option<usize>) -> Result<(), Error> {
match (len, &self.settings.array) {
- (Some(0...1), _) | (_, &None) => {
+ (Some(0..=1), _) | (_, &None) => {
if first.get() {
self.dst.push_str("[")
} else {
@@ -517,7 +514,7 @@ impl<'a> Serializer<'a> {
fn escape_key(&mut self, key: &str) -> Result<(), Error> {
let ok = key.chars().all(|c| match c {
- 'a'...'z' | 'A'...'Z' | '0'...'9' | '-' | '_' => true,
+ 'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' => true,
_ => false,
});
if ok {
@@ -666,7 +663,7 @@ impl<'a> Serializer<'a> {
Ok(())
}
- fn emit_table_header(&mut self, state: &State) -> Result<(), Error> {
+ fn emit_table_header(&mut self, state: &State<'_>) -> Result<(), Error> {
let array_of_tables = match *state {
State::End => return Ok(()),
State::Array { .. } => true,
@@ -730,7 +727,7 @@ impl<'a> Serializer<'a> {
Ok(())
}
- fn emit_key_part(&mut self, key: &State) -> Result<bool, Error> {
+ fn emit_key_part(&mut self, key: &State<'_>) -> Result<bool, Error> {
match *key {
State::Array { parent, .. } => self.emit_key_part(parent),
State::End => Ok(true),
@@ -997,7 +994,7 @@ impl<'a, 'b> ser::SerializeSeq for SerializeSeq<'a, 'b> {
match self.type_.get() {
Some("table") => return Ok(()),
Some(_) => match (self.len, &self.ser.settings.array) {
- (Some(0...1), _) | (_, &None) => {
+ (Some(0..=1), _) | (_, &None) => {
self.ser.dst.push_str("]");
}
(_, &Some(ref a)) => {
@@ -1531,7 +1528,7 @@ impl ser::Serializer for StringExtractor {
}
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::UnsupportedType => "unsupported Rust type".fmt(f),
Error::KeyNotString => "map key was not a string".fmt(f),
@@ -1584,8 +1581,7 @@ enum Category {
/// helper can be used like so:
///
/// ```rust
-/// # #[macro_use] extern crate serde_derive;
-/// # extern crate toml;
+/// # use serde_derive::Serialize;
/// # use std::collections::HashMap;
/// #[derive(Serialize)]
/// struct Manifest {
diff --git a/src/spanned.rs b/src/spanned.rs
index fb476ee..cd02c87 100644
--- a/src/spanned.rs
+++ b/src/spanned.rs
@@ -1,8 +1,5 @@
//! ```
-//! #[macro_use]
-//! extern crate serde_derive;
-//!
-//! extern crate toml;
+//! use serde_derive::Deserialize;
//! use toml::Spanned;
//!
//! #[derive(Deserialize)]
@@ -93,7 +90,7 @@ where
{
type Value = Spanned<T>;
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a TOML spanned")
}
diff --git a/src/tokens.rs b/src/tokens.rs
index 6413ce1..f9d3eb4 100644
--- a/src/tokens.rs
+++ b/src/tokens.rs
@@ -294,8 +294,8 @@ impl<'a> Tokenizer<'a> {
&mut self,
delim: char,
start: usize,
- new_ch: &mut FnMut(
- &mut Tokenizer,
+ new_ch: &mut dyn FnMut(
+ &mut Tokenizer<'_>,
&mut MaybeString,
bool,
usize,
@@ -514,7 +514,7 @@ impl MaybeString {
}
}
- fn into_cow(self, input: &str) -> Cow<str> {
+ fn into_cow(self, input: &str) -> Cow<'_, str> {
match self {
MaybeString::NotEscaped(start) => Cow::Borrowed(&input[start..]),
MaybeString::Owned(s) => Cow::Owned(s),
@@ -665,9 +665,9 @@ mod tests {
#[test]
fn all() {
- fn t(input: &str, expected: &[((usize, usize), Token, &str)]) {
+ fn t(input: &str, expected: &[((usize, usize), Token<'_>, &str)]) {
let mut tokens = Tokenizer::new(input);
- let mut actual: Vec<((usize, usize), Token, &str)> = Vec::new();
+ let mut actual: Vec<((usize, usize), Token<'_>, &str)> = Vec::new();
while let Some((span, token)) = tokens.next().unwrap() {
actual.push((span.into(), token, &input[span.start..span.end]));
}
diff --git a/src/value.rs b/src/value.rs
index 0e463ec..8f2c6c6 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -391,7 +391,7 @@ where
}
impl fmt::Display for Value {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
crate::ser::to_string(self)
.expect("Unable to represent value as string")
.fmt(f)
@@ -462,7 +462,7 @@ impl<'de> de::Deserialize<'de> for Value {
impl<'de> de::Visitor<'de> for ValueVisitor {
type Value = Value;
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("any valid TOML value")
}
@@ -628,7 +628,7 @@ impl<'de> de::Deserializer<'de> for Value {
visitor.visit_newtype_struct(self)
}
- forward_to_deserialize_any! {
+ serde::forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
bytes byte_buf map unit_struct tuple_struct struct
tuple ignored_any identifier
@@ -1060,7 +1060,7 @@ impl<'a, 'de> de::DeserializeSeed<'de> for DatetimeOrTable<'a> {
impl<'a, 'de> de::Visitor<'de> for DatetimeOrTable<'a> {
type Value = bool;
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a string key")
}