parsers: add xso text trait implementations to types
This allows them to be used as attribute in xso-proc derived structs.
This commit is contained in:
parent
c0fc7f49cf
commit
4e9c4883a3
2 changed files with 36 additions and 1 deletions
|
|
@ -82,6 +82,11 @@ macro_rules! generate_attribute {
|
|||
})
|
||||
}
|
||||
}
|
||||
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 std::fmt::Display for $elem {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
write!(fmt, "{}", match self {
|
||||
|
|
@ -89,6 +94,11 @@ macro_rules! generate_attribute {
|
|||
})
|
||||
}
|
||||
}
|
||||
impl ::xso::IntoXmlText for $elem {
|
||||
fn into_xml_text(self) -> Result<String, xso::error::Error> {
|
||||
Ok(self.to_string())
|
||||
}
|
||||
}
|
||||
impl ::minidom::IntoAttributeValue for $elem {
|
||||
fn into_attribute_value(self) -> Option<String> {
|
||||
Some(String::from(match self {
|
||||
|
|
@ -377,6 +387,16 @@ macro_rules! generate_id {
|
|||
Ok($elem(String::from(s)))
|
||||
}
|
||||
}
|
||||
impl ::xso::FromXmlText for $elem {
|
||||
fn from_xml_text(s: String) -> Result<$elem, xso::error::Error> {
|
||||
Ok(Self(s))
|
||||
}
|
||||
}
|
||||
impl ::xso::IntoXmlText for $elem {
|
||||
fn into_xml_text(self) ->Result<String, xso::error::Error> {
|
||||
Ok(self.0)
|
||||
}
|
||||
}
|
||||
impl ::minidom::IntoAttributeValue for $elem {
|
||||
fn into_attribute_value(self) -> Option<String> {
|
||||
Some(self.0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue