parsers: replace some more generate_element! calls with derive macros

This commit is contained in:
Jonas Schäfer 2024-06-30 09:42:55 +02:00
commit 819a869ffb
10 changed files with 317 additions and 165 deletions

View file

@ -6,7 +6,11 @@
use crate::ns;
use minidom::Element;
use xso::error::{Error, FromElementError};
use xso::{
error::{Error, FromElementError, FromEventsError},
exports::rxml,
minidom_compat, AsXml, FromXml,
};
/// Requests paging through a potentially big set of items (represented by an
/// UID).
@ -67,6 +71,20 @@ impl TryFrom<Element> for SetQuery {
}
}
impl FromXml for SetQuery {
type Builder = minidom_compat::FromEventsViaElement<SetQuery>;
fn from_events(
qname: rxml::QName,
attrs: rxml::AttrMap,
) -> Result<Self::Builder, FromEventsError> {
if qname.0 != crate::ns::RSM || qname.1 != "set" {
return Err(FromEventsError::Mismatch { name: qname, attrs });
}
Self::Builder::new(qname, attrs)
}
}
impl From<SetQuery> for Element {
fn from(set: SetQuery) -> Element {
Element::builder("set", ns::RSM)
@ -93,6 +111,14 @@ impl From<SetQuery> for Element {
}
}
impl AsXml for SetQuery {
type ItemIter<'x> = minidom_compat::AsItemsViaElement<'x>;
fn as_xml_iter(&self) -> Result<Self::ItemIter<'_>, Error> {
minidom_compat::AsItemsViaElement::new(self.clone())
}
}
/// Describes the paging result of a [query](struct.SetQuery.html).
#[derive(Debug, Clone, PartialEq)]
pub struct SetResult {