Skip to content

Commit

Permalink
fix: Un-nest Debug of errors holding only 'inner'
Browse files Browse the repository at this point in the history
println!("{:#?}", toml::from_str::<i32>("").unwrap_err());

Before:

    Error {
        inner: Error {
            inner: TomlError {
                message: "invalid type: map, expected i32",
                raw: Some(
                    "",
                ),
                keys: [],
                span: Some(
                    0..0,
                ),
            },
        },
    }

After:

    TomlError {
        message: "invalid type: map, expected i32",
        raw: Some(
            "",
        ),
        keys: [],
        span: Some(
            0..0,
        ),
    }
  • Loading branch information
dtolnay committed Dec 13, 2024
1 parent 675edca commit 1bbf92a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion crates/toml/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
}

/// Errors that can occur when deserializing a type.
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(PartialEq, Eq, Clone)]
pub struct Error {
inner: crate::edit::de::Error,
}
Expand Down Expand Up @@ -87,6 +87,12 @@ impl std::fmt::Display for Error {
}
}

impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.fmt(f)
}
}

impl std::error::Error for Error {}

/// Deserialization TOML document
Expand Down
8 changes: 7 additions & 1 deletion crates/toml/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ where
}

/// Errors that can occur when serializing a type.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq)]
pub struct Error {
pub(crate) inner: crate::edit::ser::Error,
}
Expand Down Expand Up @@ -125,6 +125,12 @@ impl std::fmt::Display for Error {
}
}

impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.fmt(f)
}
}

impl std::error::Error for Error {}

/// Serialization for TOML documents.
Expand Down
8 changes: 7 additions & 1 deletion crates/toml_edit/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use table_enum::TableEnumDeserializer;
pub use value::ValueDeserializer;

/// Errors that can occur when deserializing a type.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq)]
pub struct Error {
inner: crate::TomlError,
}
Expand Down Expand Up @@ -71,6 +71,12 @@ impl std::fmt::Display for Error {
}
}

impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.fmt(f)
}
}

impl From<crate::TomlError> for Error {
fn from(e: crate::TomlError) -> Error {
Self { inner: e }
Expand Down

0 comments on commit 1bbf92a

Please sign in to comment.