1use xso::{AsXml, FromXml};
8
9use crate::{iq::Iq, message::Message, presence::Presence};
10
11#[derive(FromXml, AsXml, Debug, PartialEq)]
17#[xml()]
18pub enum Stanza {
19 #[xml(transparent)]
21 Iq(Iq),
22
23 #[xml(transparent)]
25 Message(Message),
26
27 #[xml(transparent)]
29 Presence(Presence),
30}
31
32impl From<Iq> for Stanza {
33 fn from(other: Iq) -> Self {
34 Self::Iq(other)
35 }
36}
37
38impl From<Presence> for Stanza {
39 fn from(other: Presence) -> Self {
40 Self::Presence(other)
41 }
42}
43
44impl From<Message> for Stanza {
45 fn from(other: Message) -> Self {
46 Self::Message(other)
47 }
48}
49
50impl TryFrom<Stanza> for Message {
51 type Error = Stanza;
52
53 fn try_from(other: Stanza) -> Result<Self, Stanza> {
54 match other {
55 Stanza::Message(st) => Ok(st),
56 other => Err(other),
57 }
58 }
59}
60
61impl TryFrom<Stanza> for Presence {
62 type Error = Stanza;
63
64 fn try_from(other: Stanza) -> Result<Self, Stanza> {
65 match other {
66 Stanza::Presence(st) => Ok(st),
67 other => Err(other),
68 }
69 }
70}
71
72impl TryFrom<Stanza> for Iq {
73 type Error = Stanza;
74
75 fn try_from(other: Stanza) -> Result<Self, Stanza> {
76 match other {
77 Stanza::Iq(st) => Ok(st),
78 other => Err(other),
79 }
80 }
81}