xso: add support for fallible parsing and serialisation

This commit is contained in:
Jonas Schäfer 2024-08-10 09:11:32 +02:00
commit 2ff81b3923
4 changed files with 481 additions and 0 deletions

View file

@ -68,6 +68,21 @@ impl<T: AsXml> AsXml for Box<T> {
}
}
/// Emits the items of `T` if `Ok(.)` or returns the error from `E` otherwise.
impl<T: AsXml, E> AsXml for Result<T, E>
where
for<'a> Error: From<&'a E>,
{
type ItemIter<'x> = T::ItemIter<'x> where Self: 'x;
fn as_xml_iter(&self) -> Result<Self::ItemIter<'_>, Error> {
match self {
Self::Ok(v) => Ok(v.as_xml_iter()?),
Self::Err(e) => Err(e.into()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;