Skip to content

Commit

Permalink
Relax loading XML values using FromValue
Browse files Browse the repository at this point in the history
All the ones we currently use it for implement Default, so we can just
use unwrap_or_defualt. This handles the case of empty strings, and is
probably fine for other types. It's a little weird for numbers, but 0 is
a pretty reasonable way to interpret an empty <Int></Int> tag.
  • Loading branch information
einarmo committed Jan 23, 2025
1 parent 7c4ce2f commit 9790a36
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions async-opcua-xml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ impl FromValue for bool {

impl<'input, T> XmlLoad<'input> for T
where
T: FromValue,
T: FromValue + Default,
{
fn load(node: &Node<'_, 'input>) -> Result<Self, XmlError> {
T::from_value(node, "content", node.try_contents()?)
T::from_value(node, "content", node.try_contents().unwrap_or_default())
}
}

0 comments on commit 9790a36

Please sign in to comment.