diff --git a/parsers/src/util/macros.rs b/parsers/src/util/macros.rs index d5e03fd2..e589a28a 100644 --- a/parsers/src/util/macros.rs +++ b/parsers/src/util/macros.rs @@ -275,6 +275,23 @@ macro_rules! generate_attribute { $elem($default) } } + impl ::xso::FromXmlText for $elem { + fn from_xml_text(s: String) -> Result<$elem, xso::error::Error> { + s.parse().map_err(xso::error::Error::text_parse_error) + } + } + impl ::xso::AsXmlText for $elem { + fn as_xml_text(&self) -> Result<::std::borrow::Cow<'_, str>, xso::error::Error> { + Ok(::std::borrow::Cow::Owned(format!("{}", self.0))) + } + + fn as_optional_xml_text(&self) -> Result>, xso::error::Error> { + match self.0 { + $default => Ok(None), + _ => Ok(Some(::std::borrow::Cow::Owned(format!("{}", self.0)))), + } + } + } ); }