Switch from toml back to toml_edit (#738)

Since now toml simply uses toml_edit, there is no reason to continue
using it as it merely increase compilation time and bloat.

Instead, we switch to toml_edit v0.18.0 with feature serde enabled.

This also remove the `CratesTomlParseError::TomlParseNonUtf8` variant
intorduced in #736.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-01-24 14:27:34 +11:00 committed by GitHub
parent 425c6c2509
commit 152ea8376b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 28 deletions

18
Cargo.lock generated
View file

@ -247,7 +247,7 @@ dependencies = [
"serde_json",
"tempfile",
"thiserror",
"toml 0.6.0",
"toml_edit",
"url",
]
@ -385,7 +385,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f1204fe51a1e56042b8ec31d6407547ecd18f596b66f470dadb9abd9be9c843"
dependencies = [
"serde",
"toml 0.5.11",
"toml",
]
[[package]]
@ -671,7 +671,7 @@ checksum = "e62abb876c07e4754fae5c14cafa77937841f01740637e17d78dc04352f32a5e"
dependencies = [
"cc",
"rustc_version",
"toml 0.5.11",
"toml",
"vswhom",
"winreg",
]
@ -2502,18 +2502,6 @@ dependencies = [
"serde",
]
[[package]]
name = "toml"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb9d890e4dc9298b70f740f615f2e05b9db37dce531f6b24fb77ac993f9f217"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.5.1"

View file

@ -21,7 +21,7 @@ serde = { version = "1.0.152", features = ["derive"] }
serde-tuple-vec-map = "1.0.1"
serde_json = "1.0.91"
thiserror = "1.0.38"
toml = "0.6.0"
toml_edit = { version = "0.18.0", features = ["serde"] }
url = { version = "2.3.1", features = ["serde"] }
[dev-dependencies]

View file

@ -55,7 +55,7 @@ impl CratesToml<'_> {
if vec.is_empty() {
Ok(CratesToml::default())
} else {
toml::from_str(str::from_utf8(&vec)?).map_err(CratesTomlParseError::from)
toml_edit::de::from_slice(&vec).map_err(CratesTomlParseError::from)
}
}
@ -90,7 +90,7 @@ impl CratesToml<'_> {
this: &CratesToml<'_>,
writer: &mut dyn io::Write,
) -> Result<(), CratesTomlParseError> {
let data = toml::to_string(&this)?.into_bytes();
let data = toml_edit::ser::to_vec(&this)?;
writer.write_all(&data)?;
Ok(())
}
@ -185,14 +185,11 @@ pub enum CratesTomlParseError {
#[error(transparent)]
Io(#[from] io::Error),
#[error("Failed to parse toml: File is not in valid utf-8 encodings: {0}")]
TomlParseNonUtf8(#[from] Utf8Error),
#[error(transparent)]
TomlParse(Box<toml_edit::de::Error>),
#[error(transparent)]
TomlParse(Box<toml::de::Error>),
#[error(transparent)]
TomlWrite(Box<toml::ser::Error>),
TomlWrite(Box<toml_edit::ser::Error>),
#[error(transparent)]
CvsParse(Box<CvsParseError>),
@ -204,14 +201,14 @@ impl From<CvsParseError> for CratesTomlParseError {
}
}
impl From<toml::ser::Error> for CratesTomlParseError {
fn from(e: toml::ser::Error) -> Self {
impl From<toml_edit::ser::Error> for CratesTomlParseError {
fn from(e: toml_edit::ser::Error) -> Self {
CratesTomlParseError::TomlWrite(Box::new(e))
}
}
impl From<toml::de::Error> for CratesTomlParseError {
fn from(e: toml::de::Error) -> Self {
impl From<toml_edit::de::Error> for CratesTomlParseError {
fn from(e: toml_edit::de::Error) -> Self {
CratesTomlParseError::TomlParse(Box::new(e))
}
}