From 152ea8376b814cfb4ae394b7c5580ba6fdc79e1e Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 24 Jan 2023 14:27:34 +1100 Subject: [PATCH] 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 --- Cargo.lock | 18 +++------------- crates/binstalk-manifests/Cargo.toml | 2 +- .../binstalk-manifests/src/cargo_crates_v1.rs | 21 ++++++++----------- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a2e25333..82396e69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/crates/binstalk-manifests/Cargo.toml b/crates/binstalk-manifests/Cargo.toml index d424655d..4e8e826b 100644 --- a/crates/binstalk-manifests/Cargo.toml +++ b/crates/binstalk-manifests/Cargo.toml @@ -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] diff --git a/crates/binstalk-manifests/src/cargo_crates_v1.rs b/crates/binstalk-manifests/src/cargo_crates_v1.rs index 42a58a7c..2741e5a2 100644 --- a/crates/binstalk-manifests/src/cargo_crates_v1.rs +++ b/crates/binstalk-manifests/src/cargo_crates_v1.rs @@ -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), #[error(transparent)] - TomlParse(Box), - - #[error(transparent)] - TomlWrite(Box), + TomlWrite(Box), #[error(transparent)] CvsParse(Box), @@ -204,14 +201,14 @@ impl From for CratesTomlParseError { } } -impl From for CratesTomlParseError { - fn from(e: toml::ser::Error) -> Self { +impl From for CratesTomlParseError { + fn from(e: toml_edit::ser::Error) -> Self { CratesTomlParseError::TomlWrite(Box::new(e)) } } -impl From for CratesTomlParseError { - fn from(e: toml::de::Error) -> Self { +impl From for CratesTomlParseError { + fn from(e: toml_edit::de::Error) -> Self { CratesTomlParseError::TomlParse(Box::new(e)) } }