зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1806766 - Update toml to 0.5.10. r=emilio,supply-chain-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D165710
This commit is contained in:
Родитель
9e2406b96c
Коммит
0b30b96d8b
|
@ -5531,9 +5531,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.9"
|
||||
version = "0.5.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
|
||||
checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
|
|
@ -1939,6 +1939,11 @@ who = "Mike Hommey <mh+mozilla@glandium.org>"
|
|||
criteria = "safe-to-run"
|
||||
delta = "0.1.9 -> 0.1.11"
|
||||
|
||||
[[audits.toml]]
|
||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "0.5.9 -> 0.5.10"
|
||||
|
||||
[[audits.topological-sort]]
|
||||
who = "Bobby Holley <bobbyholley@gmail.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.lock":"8b79835f7ab21184ac6f2ae2049f063d931c9e6b1b04456fc74442cc102e39a3","Cargo.toml":"6f08a9b830e6d0f5fa64e23e316f5f0dcc8695d215af060d373593ccce583797","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"9f9fabc5623932ee1ac3d4c7d00c01ce78d43e1b916844249b1991df28a58be0","examples/decode.rs":"5c1bb83eef7fdf41f7d7873db4681492ce181000669aadee8895ca21e85f0aed","examples/enum_external.rs":"360618cced5c6339afbbc8799df2c047aaeeb1fa7d840dc777c2ffd83871883e","examples/toml2json.rs":"b0256e8393f91633abaa5b5c1ce496b73efee14a81b51e4f242aae967eaf9548","src/datetime.rs":"bf3c49e818d52a85ee5762ca80ce5b0d3012b1760c2ae7daf79228316a5c5d82","src/de.rs":"8c8b5482fcfd8547f711220fa0c8d44dba58958018b7d9a6a711989946aeba0f","src/lib.rs":"7cfff3e3073b6890c679654d4e1104734d1388b21618dded989818db2cd28f1d","src/macros.rs":"81a7e1b7884714cb23af28e9415f3fe35395820edad7a534c98593d5c940ec0c","src/map.rs":"ffc5539c8884baea62ed0e2ea89b018797c5e2d285f778f1d0e124a69ec29ddc","src/ser.rs":"ca2c468b3b867d65c8d106eb4d4724b5799a20ae491db69628c7cd4a8b83d351","src/spanned.rs":"01b8776279c1ef3fe2e81188e3e8f672430220482c5765178b57dac78522b1b3","src/tokens.rs":"d2fbb19c3ec857b04612d05e07bdcb3aac98a19cba1338026238756ffdac276c","src/value.rs":"185ddf60a8e85472449b03e73f7353c3374f20cc720e32cdc33c750c2871a08b","tests/enum_external_deserialize.rs":"32515d5fa80e36efed6006da6514b5054c5c903960d9d884866d608ce9d23c35"},"package":"8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"}
|
||||
{"files":{"Cargo.lock":"07886a40f452cdca63c989a0c9988c3fe0961c9edbddfb5f69aa5af7ac0fa013","Cargo.toml":"1cc7cd84cf608c6d819db3e2097e1065188f8202dc4fb8ff8995834ee33d9c61","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"a915ead738822da2d74b883c7519d8e558299286bb823e26c7fdece901c3267e","examples/decode.rs":"5c1bb83eef7fdf41f7d7873db4681492ce181000669aadee8895ca21e85f0aed","examples/enum_external.rs":"360618cced5c6339afbbc8799df2c047aaeeb1fa7d840dc777c2ffd83871883e","examples/toml2json.rs":"b0256e8393f91633abaa5b5c1ce496b73efee14a81b51e4f242aae967eaf9548","src/datetime.rs":"fe76c72cc5da6bccbd75ae3c7cb6658e92877631a93af4b88dcf54be6b6aeaed","src/de.rs":"8646e455bd3b9147550aa5e7c9400c935f580fbc320c9573b2ece492977c606d","src/lib.rs":"d599207a47e5fef74a0eeeb12d412429c305554816a89193ebbb8242f9585681","src/macros.rs":"506f00f2c12dd973a074d3c3263b0a97288eab4bda431d76d7a2cc95c63be0e0","src/map.rs":"ffc5539c8884baea62ed0e2ea89b018797c5e2d285f778f1d0e124a69ec29ddc","src/ser.rs":"e7f1e703efc1d30b0aca55c8d3f6bd62bb163652e0680cd5aeea7bf7217ba90e","src/spanned.rs":"eb370fed2aae511150d7ece47d38c95f11519db8e0b0748524338943579fe876","src/tokens.rs":"62c38be95ac994e6ae42ff983ac3ed66d3924decfd10e929455bf9168d9a1410","src/value.rs":"185ddf60a8e85472449b03e73f7353c3374f20cc720e32cdc33c750c2871a08b","tests/enum_external_deserialize.rs":"32515d5fa80e36efed6006da6514b5054c5c903960d9d884866d608ce9d23c35"},"package":"1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"}
|
|
@ -1,61 +1,70 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "0.1.7"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.3.0"
|
||||
version = "1.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2"
|
||||
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.3"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
||||
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.24"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
|
||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.10"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
|
||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "0.2.7"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
|
||||
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.98"
|
||||
version = "1.0.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fe5626ac617da2f2d9c48af5515a21d5a480dbd151e01bb1c355e26a3e68113"
|
||||
checksum = "e326c9ec8042f1b5da33252c8a37e9ffbd2c9bef0155215b6e6c80c790e05f91"
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.84"
|
||||
version = "1.0.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4d6115a3ca25c224e409185325afc16a0d5aaaabc15c42b09587d6f1ba39a5b"
|
||||
checksum = "42a3df25b0713732468deadad63ab9da1f1fd75a48a15024b50363f128db627e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -64,9 +73,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.34"
|
||||
version = "1.0.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bdf540260cfee6da923831f4776ddc495ada940c30117977c70f1313a6130545"
|
||||
checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
@ -75,18 +84,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.24"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "734ecc29cd36e8123850d9bf21dfd62ef8300aaa8f879aabaa899721808be37c"
|
||||
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.9"
|
||||
version = "0.5.10"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
|
@ -95,7 +104,7 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
name = "unicode-ident"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
|
||||
|
|
|
@ -11,25 +11,74 @@
|
|||
|
||||
[package]
|
||||
edition = "2018"
|
||||
rust-version = "1.48.0"
|
||||
name = "toml"
|
||||
version = "0.5.9"
|
||||
version = "0.5.10"
|
||||
authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
include = [
|
||||
"src/**/*",
|
||||
"Cargo.toml",
|
||||
"LICENSE*",
|
||||
"README.md",
|
||||
"examples/**/*",
|
||||
"benches/**/*",
|
||||
"tests/**/*",
|
||||
]
|
||||
description = """
|
||||
A native Rust encoder and decoder of TOML-formatted files and streams. Provides
|
||||
implementations of the standard Serialize/Deserialize traits for TOML data to
|
||||
facilitate deserializing and serializing Rust structures.
|
||||
"""
|
||||
homepage = "https://github.com/alexcrichton/toml-rs"
|
||||
homepage = "https://github.com/toml-rs/toml"
|
||||
documentation = "https://docs.rs/toml"
|
||||
readme = "README.md"
|
||||
keywords = ["encoding"]
|
||||
keywords = [
|
||||
"encoding",
|
||||
"toml",
|
||||
]
|
||||
categories = [
|
||||
"config",
|
||||
"encoding",
|
||||
"parser-implementations",
|
||||
"parsing",
|
||||
"config",
|
||||
]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/alexcrichton/toml-rs"
|
||||
repository = "https://github.com/toml-rs/toml"
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "Unreleased"
|
||||
replace = "{{version}}"
|
||||
min = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = '\.\.\.HEAD'
|
||||
replace = "...{{tag_name}}"
|
||||
exactly = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "ReleaseDate"
|
||||
replace = "{{date}}"
|
||||
min = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "<!-- next-header -->"
|
||||
replace = """
|
||||
<!-- next-header -->
|
||||
## [Unreleased] - ReleaseDate
|
||||
"""
|
||||
exactly = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "<!-- next-url -->"
|
||||
replace = """
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/toml-rs/toml_edit/compare/{{tag_name}}...HEAD"""
|
||||
exactly = 1
|
||||
|
||||
[dependencies.indexmap]
|
||||
version = "1.0"
|
||||
|
|
|
@ -1,24 +1,15 @@
|
|||
# toml-rs
|
||||
# toml
|
||||
|
||||
[![Latest Version](https://img.shields.io/crates/v/toml.svg)](https://crates.io/crates/toml)
|
||||
[![Documentation](https://docs.rs/toml/badge.svg)](https://docs.rs/toml)
|
||||
|
||||
A [TOML][toml] decoder and encoder for Rust. This library is currently compliant
|
||||
with the v0.5.0 version of TOML. This library will also likely continue to stay
|
||||
up to date with the TOML specification as changes happen.
|
||||
A [serde]-compatible [TOML][toml] decoder and encoder for Rust.
|
||||
|
||||
For format-preserving edits or finer control over output, see [toml_edit]
|
||||
|
||||
[serde]: https://serde.rs/
|
||||
[toml]: https://github.com/toml-lang/toml
|
||||
|
||||
```toml
|
||||
# Cargo.toml
|
||||
[dependencies]
|
||||
toml = "0.5"
|
||||
```
|
||||
|
||||
This crate also supports serialization/deserialization through the
|
||||
[serde](https://serde.rs) crate on crates.io. Currently the older `rustc-serialize`
|
||||
crate is not supported in the 0.3+ series of the `toml` crate, but 0.2 can be
|
||||
used for that support.
|
||||
[toml_edit]: https://docs.rs/toml_edit
|
||||
|
||||
# License
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ use serde::{de, ser};
|
|||
/// [Local Date-Time]: https://toml.io/en/v1.0.0#local-date-time
|
||||
/// [Local Date]: https://toml.io/en/v1.0.0#local-date
|
||||
/// [Local Time]: https://toml.io/en/v1.0.0#local-time
|
||||
#[derive(PartialEq, Clone)]
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct Datetime {
|
||||
/// Optional date.
|
||||
/// Required for: *Offset Date-Time*, *Local Date-Time*, *Local Date*.
|
||||
|
@ -120,7 +120,7 @@ pub const NAME: &str = "$__toml_private_Datetime";
|
|||
/// > ```
|
||||
///
|
||||
/// [Local Date]: https://toml.io/en/v1.0.0#local-date
|
||||
#[derive(PartialEq, Clone)]
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct Date {
|
||||
/// Year: four digits
|
||||
pub year: u16,
|
||||
|
@ -150,7 +150,7 @@ pub struct Date {
|
|||
/// > must be truncated, not rounded.
|
||||
///
|
||||
/// [Local Time]: https://toml.io/en/v1.0.0#local-time
|
||||
#[derive(PartialEq, Clone)]
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct Time {
|
||||
/// Hour: 0 to 23
|
||||
pub hour: u8,
|
||||
|
@ -164,7 +164,7 @@ pub struct Time {
|
|||
|
||||
/// A parsed TOML time offset
|
||||
///
|
||||
#[derive(PartialEq, Clone)]
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub enum Offset {
|
||||
/// > A suffix which, when applied to a time, denotes a UTC offset of 00:00;
|
||||
/// > often spoken "Zulu" from the ICAO phonetic alphabet representation of
|
||||
|
@ -419,7 +419,7 @@ impl FromStr for Datetime {
|
|||
|
||||
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'),
|
||||
Some(c) if ('0'..='9').contains(&c) => Ok(c as u8 - b'0'),
|
||||
_ => Err(DatetimeParseError { _private: () }),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,17 +60,15 @@ where
|
|||
/// name: String,
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let config: Config = toml::from_str(r#"
|
||||
/// title = 'TOML Example'
|
||||
/// let config: Config = toml::from_str(r#"
|
||||
/// title = 'TOML Example'
|
||||
///
|
||||
/// [owner]
|
||||
/// name = 'Lisa'
|
||||
/// "#).unwrap();
|
||||
/// [owner]
|
||||
/// name = 'Lisa'
|
||||
/// "#).unwrap();
|
||||
///
|
||||
/// assert_eq!(config.title, "TOML Example");
|
||||
/// assert_eq!(config.owner.name, "Lisa");
|
||||
/// }
|
||||
/// assert_eq!(config.title, "TOML Example");
|
||||
/// assert_eq!(config.owner.name, "Lisa");
|
||||
/// ```
|
||||
pub fn from_str<'de, T>(s: &'de str) -> Result<T, Error>
|
||||
where
|
||||
|
@ -100,6 +98,7 @@ struct ErrorInner {
|
|||
|
||||
/// Errors that can occur when deserializing a type.
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[non_exhaustive]
|
||||
enum ErrorKind {
|
||||
/// EOF was reached when looking for a value
|
||||
UnexpectedEof,
|
||||
|
@ -193,9 +192,6 @@ enum ErrorKind {
|
|||
|
||||
/// Unquoted string was found when quoted one was expected
|
||||
UnquotedString,
|
||||
|
||||
#[doc(hidden)]
|
||||
__Nonexhaustive,
|
||||
}
|
||||
|
||||
/// Deserialization implementation for TOML.
|
||||
|
@ -328,7 +324,7 @@ impl<'de, 'b> de::Deserializer<'de> for &'b mut Deserializer<'de> {
|
|||
// by their index in the passed slice. We use a list as the implementation
|
||||
// uses this data structure for arrays as well as tables,
|
||||
// so if any top level [[name]] array contains multiple entries,
|
||||
// there are multiple entires in the list.
|
||||
// there are multiple entries in the list.
|
||||
// The lookup is performed in the `SeqAccess` implementation of `MapVisitor`.
|
||||
// The lists are ordered, which we exploit in the search code by using
|
||||
// bisection.
|
||||
|
@ -527,8 +523,8 @@ impl<'de, 'b> de::MapAccess<'de> for MapVisitor<'de, 'b> {
|
|||
cur: 0,
|
||||
max: self.max,
|
||||
array,
|
||||
table_indices: &*self.table_indices,
|
||||
table_pindices: &*self.table_pindices,
|
||||
table_indices: self.table_indices,
|
||||
table_pindices: self.table_pindices,
|
||||
tables: &mut *self.tables,
|
||||
de: &mut *self.de,
|
||||
});
|
||||
|
@ -589,10 +585,10 @@ impl<'de, 'b> de::SeqAccess<'de> for MapVisitor<'de, 'b> {
|
|||
max: next,
|
||||
cur: 0,
|
||||
array: false,
|
||||
table_indices: &*self.table_indices,
|
||||
table_pindices: &*self.table_pindices,
|
||||
tables: &mut self.tables,
|
||||
de: &mut self.de,
|
||||
table_indices: self.table_indices,
|
||||
table_pindices: self.table_pindices,
|
||||
tables: self.tables,
|
||||
de: self.de,
|
||||
})?;
|
||||
self.cur_parent = next;
|
||||
Ok(Some(ret))
|
||||
|
@ -644,7 +640,7 @@ impl<'de, 'b> de::Deserializer<'de> for MapVisitor<'de, 'b> {
|
|||
{
|
||||
if name == spanned::NAME
|
||||
&& fields == [spanned::START, spanned::END, spanned::VALUE]
|
||||
&& !(self.array && !self.values.peek().is_none())
|
||||
&& !(self.array && self.values.peek().is_some())
|
||||
{
|
||||
// TODO we can't actually emit spans here for the *entire* table/array
|
||||
// due to the format that toml uses. Setting the start and end to 0 is
|
||||
|
@ -721,7 +717,7 @@ impl<'a> StrDeserializer<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> de::IntoDeserializer<'a, Error> for StrDeserializer<'a> {
|
||||
impl<'a> de::IntoDeserializer<'a, Error> for StrDeserializer<'a> {
|
||||
type Deserializer = Self;
|
||||
|
||||
fn into_deserializer(self) -> Self::Deserializer {
|
||||
|
@ -1536,7 +1532,7 @@ impl<'a> Deserializer<'a> {
|
|||
.unwrap_or_else(|| header.1.len());
|
||||
Ok((
|
||||
Value {
|
||||
e: E::DottedTable(table.values.unwrap_or_else(Vec::new)),
|
||||
e: E::DottedTable(table.values.unwrap_or_default()),
|
||||
start,
|
||||
end,
|
||||
},
|
||||
|
@ -1554,12 +1550,12 @@ impl<'a> Deserializer<'a> {
|
|||
start,
|
||||
end,
|
||||
};
|
||||
if s.starts_with("0x") {
|
||||
self.integer(&s[2..], 16).map(to_integer)
|
||||
} else if s.starts_with("0o") {
|
||||
self.integer(&s[2..], 8).map(to_integer)
|
||||
} else if s.starts_with("0b") {
|
||||
self.integer(&s[2..], 2).map(to_integer)
|
||||
if let Some(value) = s.strip_prefix("0x") {
|
||||
self.integer(value, 16).map(to_integer)
|
||||
} else if let Some(value) = s.strip_prefix("0o") {
|
||||
self.integer(value, 8).map(to_integer)
|
||||
} else if let Some(value) = s.strip_prefix("0b") {
|
||||
self.integer(value, 2).map(to_integer)
|
||||
} else if s.contains('e') || s.contains('E') {
|
||||
self.float(s, None).map(|f| Value {
|
||||
e: E::Float(f),
|
||||
|
@ -1620,10 +1616,10 @@ impl<'a> Deserializer<'a> {
|
|||
let allow_leading_zeros = radix != 10;
|
||||
let (prefix, suffix) = self.parse_integer(s, allow_sign, allow_leading_zeros, radix)?;
|
||||
let start = self.tokens.substr_offset(s);
|
||||
if suffix != "" {
|
||||
if !suffix.is_empty() {
|
||||
return Err(self.error(start, ErrorKind::NumberInvalid));
|
||||
}
|
||||
i64::from_str_radix(&prefix.replace("_", "").trim_start_matches('+'), radix)
|
||||
i64::from_str_radix(prefix.replace('_', "").trim_start_matches('+'), radix)
|
||||
.map_err(|_e| self.error(start, ErrorKind::NumberInvalid))
|
||||
}
|
||||
|
||||
|
@ -1675,7 +1671,7 @@ impl<'a> Deserializer<'a> {
|
|||
|
||||
let mut fraction = None;
|
||||
if let Some(after) = after_decimal {
|
||||
if suffix != "" {
|
||||
if !suffix.is_empty() {
|
||||
return Err(self.error(start, ErrorKind::NumberInvalid));
|
||||
}
|
||||
let (a, b) = self.parse_integer(after, false, true, 10)?;
|
||||
|
@ -1694,7 +1690,7 @@ impl<'a> Deserializer<'a> {
|
|||
} else {
|
||||
self.parse_integer(&suffix[1..], true, true, 10)?
|
||||
};
|
||||
if b != "" {
|
||||
if !b.is_empty() {
|
||||
return Err(self.error(start, ErrorKind::NumberInvalid));
|
||||
}
|
||||
exponent = Some(a);
|
||||
|
@ -1708,11 +1704,11 @@ impl<'a> Deserializer<'a> {
|
|||
.filter(|c| *c != '_')
|
||||
.collect::<String>();
|
||||
if let Some(fraction) = fraction {
|
||||
number.push_str(".");
|
||||
number.push('.');
|
||||
number.extend(fraction.chars().filter(|c| *c != '_'));
|
||||
}
|
||||
if let Some(exponent) = exponent {
|
||||
number.push_str("E");
|
||||
number.push('E');
|
||||
number.extend(exponent.chars().filter(|c| *c != '_'));
|
||||
}
|
||||
number
|
||||
|
@ -1854,8 +1850,7 @@ impl<'a> Deserializer<'a> {
|
|||
}
|
||||
|
||||
fn dotted_key(&mut self) -> Result<Vec<(Span, Cow<'a, str>)>, Error> {
|
||||
let mut result = Vec::new();
|
||||
result.push(self.table_key()?);
|
||||
let mut result = vec![self.table_key()?];
|
||||
self.eat_whitespace()?;
|
||||
while self.eat(Token::Period)? {
|
||||
self.eat_whitespace()?;
|
||||
|
@ -1865,7 +1860,7 @@ impl<'a> Deserializer<'a> {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
/// Stores a value in the appropriate hierachical structure positioned based on the dotted key.
|
||||
/// Stores a value in the appropriate hierarchical structure positioned based on the dotted key.
|
||||
///
|
||||
/// Given the following definition: `multi.part.key = "value"`, `multi` and `part` are
|
||||
/// intermediate parts which are mapped to the relevant fields in the deserialized type's data
|
||||
|
@ -2149,7 +2144,6 @@ impl fmt::Display for Error {
|
|||
f,
|
||||
"invalid TOML value, did you mean to use a quoted string?"
|
||||
)?,
|
||||
ErrorKind::__Nonexhaustive => panic!(),
|
||||
}
|
||||
|
||||
if !self.inner.key.is_empty() {
|
||||
|
@ -2211,7 +2205,7 @@ impl<'a> Header<'a> {
|
|||
if self.first || self.tokens.eat(Token::Period)? {
|
||||
self.first = false;
|
||||
self.tokens.eat_whitespace()?;
|
||||
self.tokens.table_key().map(|t| t).map(Some)
|
||||
self.tokens.table_key().map(Some)
|
||||
} else {
|
||||
self.tokens.expect(Token::RightBracket)?;
|
||||
if self.array {
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
//! A [TOML]-parsing library
|
||||
//!
|
||||
//! This library implements a [TOML] v0.5.0 compatible parser,
|
||||
//! primarily supporting the [`serde`] library for encoding/decoding
|
||||
//! various types in Rust.
|
||||
//! A [serde]-compatible [TOML]-parsing library
|
||||
//!
|
||||
//! TOML itself is a simple, ergonomic, and readable configuration format:
|
||||
//!
|
||||
|
@ -143,8 +139,8 @@
|
|||
//! [TOML]: https://github.com/toml-lang/toml
|
||||
//! [Cargo]: https://crates.io/
|
||||
//! [`serde`]: https://serde.rs/
|
||||
//! [serde]: https://serde.rs/
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/toml/0.5")]
|
||||
#![deny(missing_docs)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
// Makes rustc abort compilation if there are any unsafe blocks in the crate.
|
||||
|
|
|
@ -7,26 +7,24 @@ use crate::value::{Array, Table, Value};
|
|||
/// [`toml::Value`]: value/enum.Value.html
|
||||
///
|
||||
/// ```rust
|
||||
/// fn main() {
|
||||
/// let cargo_toml = toml::toml! {
|
||||
/// [package]
|
||||
/// name = "toml"
|
||||
/// version = "0.4.5"
|
||||
/// authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
/// let cargo_toml = toml::toml! {
|
||||
/// [package]
|
||||
/// name = "toml"
|
||||
/// version = "0.4.5"
|
||||
/// authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
///
|
||||
/// [badges]
|
||||
/// travis-ci = { repository = "alexcrichton/toml-rs" }
|
||||
/// [badges]
|
||||
/// travis-ci = { repository = "alexcrichton/toml-rs" }
|
||||
///
|
||||
/// [dependencies]
|
||||
/// serde = "1.0"
|
||||
/// [dependencies]
|
||||
/// serde = "1.0"
|
||||
///
|
||||
/// [dev-dependencies]
|
||||
/// serde_derive = "1.0"
|
||||
/// serde_json = "1.0"
|
||||
/// };
|
||||
/// [dev-dependencies]
|
||||
/// serde_derive = "1.0"
|
||||
/// serde_json = "1.0"
|
||||
/// };
|
||||
///
|
||||
/// println!("{:#?}", cargo_toml);
|
||||
/// }
|
||||
/// println!("{:#?}", cargo_toml);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! toml {
|
||||
|
@ -432,16 +430,15 @@ fn traverse<'a>(root: &'a mut Value, path: &[&str]) -> &'a mut Value {
|
|||
for &key in path {
|
||||
// Lexical lifetimes :D
|
||||
let cur1 = cur;
|
||||
let cur2;
|
||||
|
||||
// From the TOML spec:
|
||||
//
|
||||
// > Each double-bracketed sub-table will belong to the most recently
|
||||
// > defined table element above it.
|
||||
if cur1.is_array() {
|
||||
cur2 = cur1.as_array_mut().unwrap().last_mut().unwrap();
|
||||
let cur2 = if cur1.is_array() {
|
||||
cur1.as_array_mut().unwrap().last_mut().unwrap()
|
||||
} else {
|
||||
cur2 = cur1;
|
||||
cur1
|
||||
};
|
||||
|
||||
// We are about to index into this value, so it better be a table.
|
||||
|
|
|
@ -70,19 +70,17 @@ where
|
|||
/// enabled: bool,
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let config = Config {
|
||||
/// database: Database {
|
||||
/// ip: "192.168.1.1".to_string(),
|
||||
/// port: vec![8001, 8002, 8003],
|
||||
/// connection_max: 5000,
|
||||
/// enabled: false,
|
||||
/// },
|
||||
/// };
|
||||
/// let config = Config {
|
||||
/// database: Database {
|
||||
/// ip: "192.168.1.1".to_string(),
|
||||
/// port: vec![8001, 8002, 8003],
|
||||
/// connection_max: 5000,
|
||||
/// enabled: false,
|
||||
/// },
|
||||
/// };
|
||||
///
|
||||
/// let toml = toml::to_string(&config).unwrap();
|
||||
/// println!("{}", toml)
|
||||
/// }
|
||||
/// let toml = toml::to_string(&config).unwrap();
|
||||
/// println!("{}", toml)
|
||||
/// ```
|
||||
pub fn to_string<T: ?Sized>(value: &T) -> Result<String, Error>
|
||||
where
|
||||
|
@ -108,6 +106,7 @@ where
|
|||
|
||||
/// Errors that can occur when serializing a type.
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub enum Error {
|
||||
/// Indicates that a Rust type was requested to be serialized but it was not
|
||||
/// supported.
|
||||
|
@ -124,7 +123,7 @@ pub enum Error {
|
|||
#[doc(hidden)]
|
||||
KeyNewline,
|
||||
|
||||
/// An array had to be homogenous, but now it is allowed to be heterogenous.
|
||||
/// An array had to be homogeneous, but now it is allowed to be heterogeneous.
|
||||
#[doc(hidden)]
|
||||
ArrayMixedType,
|
||||
|
||||
|
@ -145,13 +144,10 @@ pub enum Error {
|
|||
/// A custom error which could be generated when serializing a particular
|
||||
/// type.
|
||||
Custom(String),
|
||||
|
||||
#[doc(hidden)]
|
||||
__Nonexhaustive,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
/// Internal place for holding array setings
|
||||
/// Internal place for holding array settings
|
||||
struct ArraySettings {
|
||||
indent: usize,
|
||||
trailing_comma: bool,
|
||||
|
@ -427,7 +423,7 @@ impl<'a> Serializer<'a> {
|
|||
self.emit_key(type_)?;
|
||||
write!(self.dst, "{}", t).map_err(ser::Error::custom)?;
|
||||
if let State::Table { .. } = self.state {
|
||||
self.dst.push_str("\n");
|
||||
self.dst.push('\n');
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -478,7 +474,7 @@ impl<'a> Serializer<'a> {
|
|||
match (len, &self.settings.array) {
|
||||
(Some(0..=1), _) | (_, &None) => {
|
||||
if first.get() {
|
||||
self.dst.push_str("[")
|
||||
self.dst.push('[')
|
||||
} else {
|
||||
self.dst.push_str(", ")
|
||||
}
|
||||
|
@ -490,7 +486,7 @@ impl<'a> Serializer<'a> {
|
|||
self.dst.push_str(",\n")
|
||||
}
|
||||
for _ in 0..a.indent {
|
||||
self.dst.push_str(" ");
|
||||
self.dst.push(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -509,11 +505,10 @@ impl<'a> Serializer<'a> {
|
|||
}
|
||||
|
||||
fn escape_key(&mut self, key: &str) -> Result<(), Error> {
|
||||
let ok = key.len() > 0
|
||||
&& key.chars().all(|c| match c {
|
||||
'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' => true,
|
||||
_ => false,
|
||||
});
|
||||
let ok = !key.is_empty()
|
||||
&& key
|
||||
.chars()
|
||||
.all(|c| matches!(c,'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_'));
|
||||
if ok {
|
||||
write!(self.dst, "{}", key).map_err(ser::Error::custom)?;
|
||||
} else {
|
||||
|
@ -715,13 +710,13 @@ impl<'a> Serializer<'a> {
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
self.dst.push_str("[");
|
||||
self.dst.push('[');
|
||||
if array_of_tables {
|
||||
self.dst.push_str("[");
|
||||
self.dst.push('[');
|
||||
}
|
||||
self.emit_key_part(state)?;
|
||||
if array_of_tables {
|
||||
self.dst.push_str("]");
|
||||
self.dst.push(']');
|
||||
}
|
||||
self.dst.push_str("]\n");
|
||||
Ok(())
|
||||
|
@ -740,7 +735,7 @@ impl<'a> Serializer<'a> {
|
|||
table_emitted.set(true);
|
||||
let first = self.emit_key_part(parent)?;
|
||||
if !first {
|
||||
self.dst.push_str(".");
|
||||
self.dst.push('.');
|
||||
}
|
||||
self.escape_key(key)?;
|
||||
Ok(false)
|
||||
|
@ -838,7 +833,7 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> {
|
|||
self.emit_key(ArrayState::Started)?;
|
||||
self.emit_str(value, false)?;
|
||||
if let State::Table { .. } = self.state {
|
||||
self.dst.push_str("\n");
|
||||
self.dst.push('\n');
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -999,11 +994,11 @@ impl<'a, 'b> ser::SerializeSeq for SerializeSeq<'a, 'b> {
|
|||
Some(ArrayState::StartedAsATable) => return Ok(()),
|
||||
Some(ArrayState::Started) => match (self.len, &self.ser.settings.array) {
|
||||
(Some(0..=1), _) | (_, &None) => {
|
||||
self.ser.dst.push_str("]");
|
||||
self.ser.dst.push(']');
|
||||
}
|
||||
(_, &Some(ref a)) => {
|
||||
if a.trailing_comma {
|
||||
self.ser.dst.push_str(",");
|
||||
self.ser.dst.push(',');
|
||||
}
|
||||
self.ser.dst.push_str("\n]");
|
||||
}
|
||||
|
@ -1015,7 +1010,7 @@ impl<'a, 'b> ser::SerializeSeq for SerializeSeq<'a, 'b> {
|
|||
}
|
||||
}
|
||||
if let State::Table { .. } = self.ser.state {
|
||||
self.ser.dst.push_str("\n");
|
||||
self.ser.dst.push('\n');
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1145,7 +1140,7 @@ impl<'a, 'b> ser::SerializeStruct for SerializeTable<'a, 'b> {
|
|||
match *self {
|
||||
SerializeTable::Datetime(ref mut ser) => {
|
||||
if key == datetime::FIELD {
|
||||
value.serialize(DateStrEmitter(&mut *ser))?;
|
||||
value.serialize(DateStrEmitter(*ser))?;
|
||||
} else {
|
||||
return Err(Error::DateInvalid);
|
||||
}
|
||||
|
@ -1543,7 +1538,6 @@ impl fmt::Display for Error {
|
|||
Error::Custom(ref s) => s.fmt(f),
|
||||
Error::KeyNewline => unreachable!(),
|
||||
Error::ArrayMixedType => unreachable!(),
|
||||
Error::__Nonexhaustive => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,16 +20,14 @@ pub(crate) const VALUE: &str = "$__toml_private_value";
|
|||
/// s: Spanned<String>,
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let t = "s = \"value\"\n";
|
||||
/// let t = "s = \"value\"\n";
|
||||
///
|
||||
/// let u: Value = toml::from_str(t).unwrap();
|
||||
/// let u: Value = toml::from_str(t).unwrap();
|
||||
///
|
||||
/// assert_eq!(u.s.start(), 4);
|
||||
/// assert_eq!(u.s.end(), 11);
|
||||
/// assert_eq!(u.s.get_ref(), "value");
|
||||
/// assert_eq!(u.s.into_inner(), String::from("value"));
|
||||
/// }
|
||||
/// assert_eq!(u.s.start(), 4);
|
||||
/// assert_eq!(u.s.end(), 11);
|
||||
/// assert_eq!(u.s.get_ref(), "value");
|
||||
/// assert_eq!(u.s.into_inner(), String::from("value"));
|
||||
/// ```
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Spanned<T> {
|
||||
|
@ -75,7 +73,7 @@ impl<T> Spanned<T> {
|
|||
|
||||
impl Borrow<str> for Spanned<String> {
|
||||
fn borrow(&self) -> &str {
|
||||
&self.get_ref()
|
||||
self.get_ref()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -278,7 +278,7 @@ impl<'a> Tokenizer<'a> {
|
|||
|
||||
fn comment_token(&mut self, start: usize) -> Token<'a> {
|
||||
while let Some((_, ch)) = self.chars.clone().next() {
|
||||
if ch != '\t' && (ch < '\u{20}' || ch > '\u{10ffff}') {
|
||||
if ch != '\t' && !('\u{20}'..='\u{10ffff}').contains(&ch) {
|
||||
break;
|
||||
}
|
||||
self.one();
|
||||
|
@ -286,6 +286,7 @@ impl<'a> Tokenizer<'a> {
|
|||
Comment(&self.input[start..self.current()])
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn read_string(
|
||||
&mut self,
|
||||
delim: char,
|
||||
|
@ -364,7 +365,7 @@ impl<'a> Tokenizer<'a> {
|
|||
|
||||
fn literal_string(&mut self, start: usize) -> Result<Token<'a>, Error> {
|
||||
self.read_string('\'', start, &mut |_me, val, _multi, i, ch| {
|
||||
if ch == '\u{09}' || ('\u{20}' <= ch && ch <= '\u{10ffff}' && ch != '\u{7f}') {
|
||||
if ch == '\u{09}' || (('\u{20}'..='\u{10ffff}').contains(&ch) && ch != '\u{7f}') {
|
||||
val.push(ch);
|
||||
Ok(())
|
||||
} else {
|
||||
|
@ -419,7 +420,7 @@ impl<'a> Tokenizer<'a> {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
ch if ch == '\u{09}' || ('\u{20}' <= ch && ch <= '\u{10ffff}' && ch != '\u{7f}') => {
|
||||
ch if ch == '\u{09}' || (('\u{20}'..='\u{10ffff}').contains(&ch) && ch != '\u{7f}') => {
|
||||
val.push(ch);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -431,7 +432,7 @@ impl<'a> Tokenizer<'a> {
|
|||
let mut buf = StdString::with_capacity(len);
|
||||
for _ in 0..len {
|
||||
match self.one() {
|
||||
Some((_, ch)) if ch as u32 <= 0x7F && ch.is_digit(16) => buf.push(ch),
|
||||
Some((_, ch)) if ch as u32 <= 0x7F && ch.is_ascii_hexdigit() => buf.push(ch),
|
||||
Some((i, ch)) => return Err(Error::InvalidHexEscape(i, ch)),
|
||||
None => return Err(Error::UnterminatedString(start)),
|
||||
}
|
||||
|
@ -506,6 +507,7 @@ impl MaybeString {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn to_owned(&mut self, input: &str) {
|
||||
match *self {
|
||||
MaybeString::NotEscaped(start) => {
|
||||
|
@ -524,9 +526,9 @@ impl MaybeString {
|
|||
}
|
||||
|
||||
fn is_keylike(ch: char) -> bool {
|
||||
('A' <= ch && ch <= 'Z')
|
||||
|| ('a' <= ch && ch <= 'z')
|
||||
|| ('0' <= ch && ch <= '9')
|
||||
('A'..='Z').contains(&ch)
|
||||
|| ('a'..='z').contains(&ch)
|
||||
|| ('0'..='9').contains(&ch)
|
||||
|| ch == '-'
|
||||
|| ch == '_'
|
||||
}
|
||||
|
@ -580,7 +582,7 @@ mod tests {
|
|||
Token::String {
|
||||
src: input,
|
||||
val: Cow::Borrowed(val),
|
||||
multiline: multiline,
|
||||
multiline,
|
||||
}
|
||||
);
|
||||
assert!(t.next().unwrap().is_none());
|
||||
|
@ -606,7 +608,7 @@ mod tests {
|
|||
Token::String {
|
||||
src: input,
|
||||
val: Cow::Borrowed(val),
|
||||
multiline: multiline,
|
||||
multiline,
|
||||
}
|
||||
);
|
||||
assert!(t.next().unwrap().is_none());
|
||||
|
|
Загрузка…
Ссылка в новой задаче