2018 edition idioms.
This commit is contained in:
parent
68fd59c78d
commit
0737f0b27a
|
@ -3,9 +3,7 @@
|
||||||
|
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
extern crate toml;
|
use serde_derive::Deserialize;
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
/// This is what we're going to decode into. Each field is optional, meaning
|
/// This is what we're going to decode into. Each field is optional, meaning
|
||||||
/// that it doesn't have to be present in TOML.
|
/// that it doesn't have to be present in TOML.
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
|
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
extern crate toml;
|
use serde_derive::Deserialize;
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
/// This is what we're going to decode into.
|
/// This is what we're going to decode into.
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
extern crate serde_json;
|
|
||||||
extern crate toml;
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
|
@ -65,13 +65,13 @@ enum Offset {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Datetime {
|
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)
|
fmt::Display::fmt(self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Datetime {
|
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 {
|
if let Some(ref date) = self.date {
|
||||||
write!(f, "{}", date)?;
|
write!(f, "{}", date)?;
|
||||||
}
|
}
|
||||||
|
@ -89,13 +89,13 @@ impl fmt::Display for Datetime {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Date {
|
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)
|
write!(f, "{:04}-{:02}-{:02}", self.year, self.month, self.day)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Time {
|
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)?;
|
write!(f, "{:02}:{:02}:{:02}", self.hour, self.minute, self.second)?;
|
||||||
if self.nanosecond != 0 {
|
if self.nanosecond != 0 {
|
||||||
let s = format!("{:09}", self.nanosecond);
|
let s = format!("{:09}", self.nanosecond);
|
||||||
|
@ -106,7 +106,7 @@ impl fmt::Display for Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Offset {
|
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 {
|
match *self {
|
||||||
Offset::Z => write!(f, "Z"),
|
Offset::Z => write!(f, "Z"),
|
||||||
Offset::Custom { hours, minutes } => write!(f, "{:+03}:{:02}", hours, minutes),
|
Offset::Custom { hours, minutes } => write!(f, "{:+03}:{:02}", hours, minutes),
|
||||||
|
@ -207,7 +207,7 @@ impl FromStr for Datetime {
|
||||||
let mut end = whole.len();
|
let mut end = whole.len();
|
||||||
for (i, byte) in whole.bytes().enumerate() {
|
for (i, byte) in whole.bytes().enumerate() {
|
||||||
match byte {
|
match byte {
|
||||||
b'0'...b'9' => {
|
b'0'..=b'9' => {
|
||||||
if i < 9 {
|
if i < 9 {
|
||||||
let p = 10_u32.pow(8 - i as u32);
|
let p = 10_u32.pow(8 - i as u32);
|
||||||
nanosecond += p * (byte - b'0') 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() {
|
match chars.next() {
|
||||||
Some(c) if '0' <= c && c <= '9' => Ok(c as u8 - b'0'),
|
Some(c) if '0' <= c && c <= '9' => Ok(c as u8 - b'0'),
|
||||||
_ => Err(DatetimeParseError { _private: () }),
|
_ => Err(DatetimeParseError { _private: () }),
|
||||||
|
@ -328,7 +328,7 @@ impl<'de> de::Deserialize<'de> for Datetime {
|
||||||
impl<'de> de::Visitor<'de> for DatetimeVisitor {
|
impl<'de> de::Visitor<'de> for DatetimeVisitor {
|
||||||
type Value = Datetime;
|
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")
|
formatter.write_str("a TOML datetime")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ impl<'de> de::Deserialize<'de> for DatetimeKey {
|
||||||
impl<'de> de::Visitor<'de> for FieldVisitor {
|
impl<'de> de::Visitor<'de> for FieldVisitor {
|
||||||
type Value = ();
|
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")
|
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 {
|
impl<'de> de::Visitor<'de> for Visitor {
|
||||||
type Value = DatetimeFromString;
|
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")
|
formatter.write_str("string containing a datetime")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ impl<'de> de::Deserialize<'de> for DatetimeFromString {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for DatetimeParseError {
|
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)
|
"failed to parse datetime".fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
src/de.rs
18
src/de.rs
|
@ -41,9 +41,7 @@ where
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #[macro_use]
|
/// use serde_derive::Deserialize;
|
||||||
/// extern crate serde_derive;
|
|
||||||
/// extern crate toml;
|
|
||||||
///
|
///
|
||||||
/// #[derive(Deserialize)]
|
/// #[derive(Deserialize)]
|
||||||
/// struct Config {
|
/// 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
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
|
||||||
bytes byte_buf map struct unit newtype_struct
|
bytes byte_buf map struct unit newtype_struct
|
||||||
ignored_any unit_struct tuple_struct tuple option identifier
|
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)
|
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
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
|
||||||
bytes byte_buf map struct unit identifier
|
bytes byte_buf map struct unit identifier
|
||||||
ignored_any unit_struct tuple_struct tuple enum
|
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
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
|
||||||
bytes byte_buf map struct option unit newtype_struct
|
bytes byte_buf map struct option unit newtype_struct
|
||||||
ignored_any unit_struct tuple_struct tuple enum identifier
|
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)
|
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
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
|
||||||
bytes byte_buf map unit identifier
|
bytes byte_buf map unit identifier
|
||||||
ignored_any unit_struct tuple_struct tuple
|
ignored_any unit_struct tuple_struct tuple
|
||||||
|
@ -796,7 +794,7 @@ impl<'de> de::Deserializer<'de> for DatetimeFieldDeserializer {
|
||||||
visitor.visit_borrowed_str(datetime::FIELD)
|
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
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
|
||||||
bytes byte_buf map struct option unit newtype_struct
|
bytes byte_buf map struct option unit newtype_struct
|
||||||
ignored_any unit_struct tuple_struct tuple enum identifier
|
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> {
|
fn array(&mut self) -> Result<(Span, Vec<Value<'a>>), Error> {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
|
|
||||||
let intermediate = |me: &mut Deserializer| {
|
let intermediate = |me: &mut Deserializer<'_>| {
|
||||||
loop {
|
loop {
|
||||||
me.eat_whitespace()?;
|
me.eat_whitespace()?;
|
||||||
if !me.eat(Token::Newline)? && !me.eat_comment()? {
|
if !me.eat(Token::Newline)? && !me.eat_comment()? {
|
||||||
|
@ -1775,7 +1773,7 @@ impl Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for 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 {
|
match self.inner.kind {
|
||||||
ErrorKind::UnexpectedEof => "unexpected eof encountered".fmt(f)?,
|
ErrorKind::UnexpectedEof => "unexpected eof encountered".fmt(f)?,
|
||||||
ErrorKind::InvalidCharInString(c) => write!(
|
ErrorKind::InvalidCharInString(c) => write!(
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -77,9 +77,7 @@
|
||||||
//! An example of deserializing with TOML is:
|
//! An example of deserializing with TOML is:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! #[macro_use]
|
//! use serde_derive::Deserialize;
|
||||||
//! extern crate serde_derive;
|
|
||||||
//! extern crate toml;
|
|
||||||
//!
|
//!
|
||||||
//! #[derive(Deserialize)]
|
//! #[derive(Deserialize)]
|
||||||
//! struct Config {
|
//! struct Config {
|
||||||
|
@ -113,9 +111,7 @@
|
||||||
//! You can serialize types in a similar fashion:
|
//! You can serialize types in a similar fashion:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! #[macro_use]
|
//! use serde_derive::Serialize;
|
||||||
//! extern crate serde_derive;
|
|
||||||
//! extern crate toml;
|
|
||||||
//!
|
//!
|
||||||
//! #[derive(Serialize)]
|
//! #[derive(Serialize)]
|
||||||
//! struct Config {
|
//! struct Config {
|
||||||
|
@ -150,11 +146,7 @@
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/toml/0.5")]
|
#![doc(html_root_url = "https://docs.rs/toml/0.5")]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
#![warn(rust_2018_idioms)]
|
||||||
#[macro_use]
|
|
||||||
extern crate serde;
|
|
||||||
#[cfg(feature = "preserve_order")]
|
|
||||||
extern crate linked_hash_map;
|
|
||||||
|
|
||||||
pub mod map;
|
pub mod map;
|
||||||
pub mod value;
|
pub mod value;
|
||||||
|
|
|
@ -7,11 +7,8 @@ use crate::value::{Array, Table, Value};
|
||||||
/// [`toml::Value`]: value/enum.Value.html
|
/// [`toml::Value`]: value/enum.Value.html
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #[macro_use]
|
|
||||||
/// extern crate toml;
|
|
||||||
///
|
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let cargo_toml = toml! {
|
/// let cargo_toml = toml::toml! {
|
||||||
/// [package]
|
/// [package]
|
||||||
/// name = "toml"
|
/// name = "toml"
|
||||||
/// version = "0.4.5"
|
/// version = "0.4.5"
|
||||||
|
|
14
src/map.rs
14
src/map.rs
|
@ -140,7 +140,7 @@ impl Map<String, Value> {
|
||||||
|
|
||||||
/// Gets the given key's corresponding entry in the map for in-place
|
/// Gets the given key's corresponding entry in the map for in-place
|
||||||
/// manipulation.
|
/// manipulation.
|
||||||
pub fn entry<S>(&mut self, key: S) -> Entry
|
pub fn entry<S>(&mut self, key: S) -> Entry<'_>
|
||||||
where
|
where
|
||||||
S: Into<String>,
|
S: Into<String>,
|
||||||
{
|
{
|
||||||
|
@ -169,7 +169,7 @@ impl Map<String, Value> {
|
||||||
|
|
||||||
/// Gets an iterator over the entries of the map.
|
/// Gets an iterator over the entries of the map.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter(&self) -> Iter {
|
pub fn iter(&self) -> Iter<'_> {
|
||||||
Iter {
|
Iter {
|
||||||
iter: self.map.iter(),
|
iter: self.map.iter(),
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ impl Map<String, Value> {
|
||||||
|
|
||||||
/// Gets a mutable iterator over the entries of the map.
|
/// Gets a mutable iterator over the entries of the map.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter_mut(&mut self) -> IterMut {
|
pub fn iter_mut(&mut self) -> IterMut<'_> {
|
||||||
IterMut {
|
IterMut {
|
||||||
iter: self.map.iter_mut(),
|
iter: self.map.iter_mut(),
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ impl Map<String, Value> {
|
||||||
|
|
||||||
/// Gets an iterator over the keys of the map.
|
/// Gets an iterator over the keys of the map.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn keys(&self) -> Keys {
|
pub fn keys(&self) -> Keys<'_> {
|
||||||
Keys {
|
Keys {
|
||||||
iter: self.map.keys(),
|
iter: self.map.keys(),
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ impl Map<String, Value> {
|
||||||
|
|
||||||
/// Gets an iterator over the values of the map.
|
/// Gets an iterator over the values of the map.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn values(&self) -> Values {
|
pub fn values(&self) -> Values<'_> {
|
||||||
Values {
|
Values {
|
||||||
iter: self.map.values(),
|
iter: self.map.values(),
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ where
|
||||||
|
|
||||||
impl Debug for Map<String, Value> {
|
impl Debug for Map<String, Value> {
|
||||||
#[inline]
|
#[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)
|
self.map.fmt(formatter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ impl<'de> de::Deserialize<'de> for Map<String, Value> {
|
||||||
impl<'de> de::Visitor<'de> for Visitor {
|
impl<'de> de::Visitor<'de> for Visitor {
|
||||||
type Value = Map<String, Value>;
|
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")
|
formatter.write_str("a map")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
src/ser.rs
24
src/ser.rs
|
@ -12,8 +12,7 @@
|
||||||
//! may use the `tables_last` function in this module like so:
|
//! may use the `tables_last` function in this module like so:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! # #[macro_use] extern crate serde_derive;
|
//! # use serde_derive::Serialize;
|
||||||
//! # extern crate toml;
|
|
||||||
//! # use std::collections::HashMap;
|
//! # use std::collections::HashMap;
|
||||||
//! #[derive(Serialize)]
|
//! #[derive(Serialize)]
|
||||||
//! struct Manifest {
|
//! struct Manifest {
|
||||||
|
@ -56,9 +55,7 @@ where
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #[macro_use]
|
/// use serde_derive::Serialize;
|
||||||
/// extern crate serde_derive;
|
|
||||||
/// extern crate toml;
|
|
||||||
///
|
///
|
||||||
/// #[derive(Serialize)]
|
/// #[derive(Serialize)]
|
||||||
/// struct Config {
|
/// struct Config {
|
||||||
|
@ -442,7 +439,7 @@ impl<'a> Serializer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursive implementation of `emit_key` above
|
// 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 {
|
match *state {
|
||||||
State::End => Ok(()),
|
State::End => Ok(()),
|
||||||
State::Array {
|
State::Array {
|
||||||
|
@ -479,7 +476,7 @@ impl<'a> Serializer<'a> {
|
||||||
|
|
||||||
fn emit_array(&mut self, first: &Cell<bool>, len: Option<usize>) -> Result<(), Error> {
|
fn emit_array(&mut self, first: &Cell<bool>, len: Option<usize>) -> Result<(), Error> {
|
||||||
match (len, &self.settings.array) {
|
match (len, &self.settings.array) {
|
||||||
(Some(0...1), _) | (_, &None) => {
|
(Some(0..=1), _) | (_, &None) => {
|
||||||
if first.get() {
|
if first.get() {
|
||||||
self.dst.push_str("[")
|
self.dst.push_str("[")
|
||||||
} else {
|
} else {
|
||||||
|
@ -517,7 +514,7 @@ impl<'a> Serializer<'a> {
|
||||||
|
|
||||||
fn escape_key(&mut self, key: &str) -> Result<(), Error> {
|
fn escape_key(&mut self, key: &str) -> Result<(), Error> {
|
||||||
let ok = key.chars().all(|c| match c {
|
let ok = key.chars().all(|c| match c {
|
||||||
'a'...'z' | 'A'...'Z' | '0'...'9' | '-' | '_' => true,
|
'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -666,7 +663,7 @@ impl<'a> Serializer<'a> {
|
||||||
Ok(())
|
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 {
|
let array_of_tables = match *state {
|
||||||
State::End => return Ok(()),
|
State::End => return Ok(()),
|
||||||
State::Array { .. } => true,
|
State::Array { .. } => true,
|
||||||
|
@ -730,7 +727,7 @@ impl<'a> Serializer<'a> {
|
||||||
Ok(())
|
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 {
|
match *key {
|
||||||
State::Array { parent, .. } => self.emit_key_part(parent),
|
State::Array { parent, .. } => self.emit_key_part(parent),
|
||||||
State::End => Ok(true),
|
State::End => Ok(true),
|
||||||
|
@ -997,7 +994,7 @@ impl<'a, 'b> ser::SerializeSeq for SerializeSeq<'a, 'b> {
|
||||||
match self.type_.get() {
|
match self.type_.get() {
|
||||||
Some("table") => return Ok(()),
|
Some("table") => return Ok(()),
|
||||||
Some(_) => match (self.len, &self.ser.settings.array) {
|
Some(_) => match (self.len, &self.ser.settings.array) {
|
||||||
(Some(0...1), _) | (_, &None) => {
|
(Some(0..=1), _) | (_, &None) => {
|
||||||
self.ser.dst.push_str("]");
|
self.ser.dst.push_str("]");
|
||||||
}
|
}
|
||||||
(_, &Some(ref a)) => {
|
(_, &Some(ref a)) => {
|
||||||
|
@ -1531,7 +1528,7 @@ impl ser::Serializer for StringExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for 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 {
|
match *self {
|
||||||
Error::UnsupportedType => "unsupported Rust type".fmt(f),
|
Error::UnsupportedType => "unsupported Rust type".fmt(f),
|
||||||
Error::KeyNotString => "map key was not a string".fmt(f),
|
Error::KeyNotString => "map key was not a string".fmt(f),
|
||||||
|
@ -1584,8 +1581,7 @@ enum Category {
|
||||||
/// helper can be used like so:
|
/// helper can be used like so:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # #[macro_use] extern crate serde_derive;
|
/// # use serde_derive::Serialize;
|
||||||
/// # extern crate toml;
|
|
||||||
/// # use std::collections::HashMap;
|
/// # use std::collections::HashMap;
|
||||||
/// #[derive(Serialize)]
|
/// #[derive(Serialize)]
|
||||||
/// struct Manifest {
|
/// struct Manifest {
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
//! ```
|
//! ```
|
||||||
//! #[macro_use]
|
//! use serde_derive::Deserialize;
|
||||||
//! extern crate serde_derive;
|
|
||||||
//!
|
|
||||||
//! extern crate toml;
|
|
||||||
//! use toml::Spanned;
|
//! use toml::Spanned;
|
||||||
//!
|
//!
|
||||||
//! #[derive(Deserialize)]
|
//! #[derive(Deserialize)]
|
||||||
|
@ -93,7 +90,7 @@ where
|
||||||
{
|
{
|
||||||
type Value = Spanned<T>;
|
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")
|
formatter.write_str("a TOML spanned")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -294,8 +294,8 @@ impl<'a> Tokenizer<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
delim: char,
|
delim: char,
|
||||||
start: usize,
|
start: usize,
|
||||||
new_ch: &mut FnMut(
|
new_ch: &mut dyn FnMut(
|
||||||
&mut Tokenizer,
|
&mut Tokenizer<'_>,
|
||||||
&mut MaybeString,
|
&mut MaybeString,
|
||||||
bool,
|
bool,
|
||||||
usize,
|
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 {
|
match self {
|
||||||
MaybeString::NotEscaped(start) => Cow::Borrowed(&input[start..]),
|
MaybeString::NotEscaped(start) => Cow::Borrowed(&input[start..]),
|
||||||
MaybeString::Owned(s) => Cow::Owned(s),
|
MaybeString::Owned(s) => Cow::Owned(s),
|
||||||
|
@ -665,9 +665,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn all() {
|
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 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() {
|
while let Some((span, token)) = tokens.next().unwrap() {
|
||||||
actual.push((span.into(), token, &input[span.start..span.end]));
|
actual.push((span.into(), token, &input[span.start..span.end]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,7 +391,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Value {
|
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)
|
crate::ser::to_string(self)
|
||||||
.expect("Unable to represent value as string")
|
.expect("Unable to represent value as string")
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
|
@ -462,7 +462,7 @@ impl<'de> de::Deserialize<'de> for Value {
|
||||||
impl<'de> de::Visitor<'de> for ValueVisitor {
|
impl<'de> de::Visitor<'de> for ValueVisitor {
|
||||||
type Value = Value;
|
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")
|
formatter.write_str("any valid TOML value")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,7 +628,7 @@ impl<'de> de::Deserializer<'de> for Value {
|
||||||
visitor.visit_newtype_struct(self)
|
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
|
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
|
bytes byte_buf map unit_struct tuple_struct struct
|
||||||
tuple ignored_any identifier
|
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> {
|
impl<'a, 'de> de::Visitor<'de> for DatetimeOrTable<'a> {
|
||||||
type Value = bool;
|
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")
|
formatter.write_str("a string key")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue