Skip to content

Commit

Permalink
Add a new error variant for pre-serialization formatting errors (#8)
Browse files Browse the repository at this point in the history
Implementing XmlSerialize on some types might require handling errors when formatting them prior to serializing to XML. This change adds a new error variant to handle such errors, using anyhow to be flexible enough to handle errors from third-party crates without having to special-case each one we want to support going forwards.
  • Loading branch information
babolivier authored May 22, 2024
1 parent 24f6adb commit 87723b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions xml_struct/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.69"
quick-xml = "0.31.0"
thiserror = "1.0.56"
xml_struct_derive = { version = "0.1.0", path = "../xml_struct_derive" }
Expand Down
6 changes: 6 additions & 0 deletions xml_struct/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,10 @@ pub trait XmlSerializeAttr {
pub enum Error {
#[error("failed to process XML document")]
Xml(#[from] quick_xml::Error),

/// An error representing a failure in formatting a data structure prior to
/// serializing it into XML. Its inner type is generic on purpose, as the
/// specific error type might be defined by a third-party crate.
#[error("failed to serialize value as text")]
Value(#[from] anyhow::Error),
}

0 comments on commit 87723b9

Please sign in to comment.