xmpp-parsers: Implement FromXmlText and AsXmlText for default types
This allows such default type wrappers to be used in other xso elements.
This commit is contained in:
parent
656125a850
commit
4e2af36186
1 changed files with 17 additions and 0 deletions
|
@ -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<Option<::std::borrow::Cow<'_, str>>, xso::error::Error> {
|
||||
match self.0 {
|
||||
$default => Ok(None),
|
||||
_ => Ok(Some(::std::borrow::Cow::Owned(format!("{}", self.0)))),
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue