xmlstream: make sink implementation generic
This allows to use any serialisable type. The advantage is that moves and clones are avoided (which would otherwise be needed to construct e.g. a XmppStreamElement from a Stanza or Message).
This commit is contained in:
parent
519718d9b5
commit
c6f928d5c8
6 changed files with 62 additions and 34 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use rand::{thread_rng, Rng};
|
||||
use xmpp_parsers::{iq::Iq, jid::Jid, message::Message, presence::Presence};
|
||||
use xso::{AsXml, FromXml};
|
||||
|
||||
use crate::xmlstream::XmppStreamElement;
|
||||
use crate::Error;
|
||||
|
|
@ -16,15 +17,19 @@ fn make_id() -> String {
|
|||
}
|
||||
|
||||
/// A stanza sent/received over the stream.
|
||||
#[derive(Debug)]
|
||||
#[derive(FromXml, AsXml, Debug)]
|
||||
#[xml()]
|
||||
pub enum Stanza {
|
||||
/// IQ stanza
|
||||
#[xml(transparent)]
|
||||
Iq(Iq),
|
||||
|
||||
/// Message stanza
|
||||
#[xml(transparent)]
|
||||
Message(Message),
|
||||
|
||||
/// Presence stanza
|
||||
#[xml(transparent)]
|
||||
Presence(Presence),
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue