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