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

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))
}
}