use quick_xml::events::{BytesStart, Event}; use crate::xml::*; use anyhow::{anyhow as ffail, Result}; pub const XMLNS: &'static str = "jabber:iq:roster"; #[derive(PartialEq, Eq, Debug)] pub struct RosterQuery; pub struct QueryParser(QueryParserInner); enum QueryParserInner { Initial, InQuery, } impl Parser for QueryParser { type Output = Result; fn consume<'a>( self: Self, namespace: quick_xml::name::ResolveResult, event: &quick_xml::events::Event<'a>, ) -> Continuation { match self.0 { QueryParserInner::Initial => match event { Event::Start(_) => Continuation::Continue(QueryParser(QueryParserInner::InQuery)), Event::Empty(_) => Continuation::Final(Ok(RosterQuery)), _ => Continuation::Final(Err(ffail!("Unexpected XML event: {event:?}"))), }, QueryParserInner::InQuery => match event { Event::End(_) => Continuation::Final(Ok(RosterQuery)), _ => Continuation::Final(Err(ffail!("Unexpected XML event: {event:?}"))), }, } } } impl FromXml for RosterQuery { type P = QueryParser; fn parse() -> Self::P { QueryParser(QueryParserInner::Initial) } } impl FromXmlTag for RosterQuery { const NAME: &'static str = "query"; const NS: &'static str = XMLNS; } impl ToXml for RosterQuery { fn serialize(&self, events: &mut Vec>) { events.push(Event::Empty(BytesStart::new(format!(r#"query xmlns="{}""#, XMLNS)))); } }