iq: Implement the Iq*Payload traits on every possible payload.

Emmanuel Gil Peyrot created

Change summary

src/bind.rs          |  4 ++++
src/blocking.rs      |  7 +++++++
src/disco.rs         |  9 +++++++++
src/ibb.rs           |  7 +++++++
src/ibr.rs           |  5 +++++
src/jingle.rs        |  3 +++
src/mam.rs           | 11 +++++++++++
src/ping.rs          |  4 ++++
src/pubsub/pubsub.rs |  5 +++++
src/roster.rs        |  5 +++++
src/version.rs       |  4 ++++
11 files changed, 64 insertions(+)

Detailed changes

src/bind.rs 🔗

@@ -12,6 +12,7 @@ use minidom::Element;
 use error::Error;
 use jid::Jid;
 use ns;
+use iq::{IqSetPayload, IqResultPayload};
 
 #[derive(Debug, Clone, PartialEq)]
 pub enum Bind {
@@ -29,6 +30,9 @@ impl Bind {
     }
 }
 
+impl IqSetPayload for Bind {}
+impl IqResultPayload for Bind {}
+
 impl TryFrom<Element> for Bind {
     type Err = Error;
 

src/blocking.rs 🔗

@@ -12,9 +12,12 @@ use minidom::Element;
 use error::Error;
 
 use ns;
+use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
 
 generate_empty_element!(BlocklistRequest, "blocklist", BLOCKING);
 
+impl IqGetPayload for BlocklistRequest {}
+
 macro_rules! generate_blocking_element {
     ($elem:ident, $name:tt) => (
         #[derive(Debug, Clone)]
@@ -59,6 +62,10 @@ generate_blocking_element!(BlocklistResult, "blocklist");
 generate_blocking_element!(Block, "block");
 generate_blocking_element!(Unblock, "unblock");
 
+impl IqResultPayload for BlocklistResult {}
+impl IqSetPayload for Block {}
+impl IqSetPayload for Unblock {}
+
 generate_empty_element!(Blocked, "blocked", BLOCKING_ERRORS);
 
 #[cfg(test)]

src/disco.rs 🔗

@@ -14,6 +14,7 @@ use jid::Jid;
 use error::Error;
 use ns;
 
+use iq::{IqGetPayload, IqResultPayload};
 use data_forms::{DataForm, DataFormType};
 
 generate_element_with_only_attributes!(
@@ -26,6 +27,8 @@ DiscoInfoQuery, "query", DISCO_INFO, [
     node: Option<String> = "node" => optional,
 ]);
 
+impl IqGetPayload for DiscoItemsQuery {}
+
 generate_element_with_only_attributes!(
 /// Structure representing a `<feature xmlns='http://jabber.org/protocol/disco#info'/>` element.
 #[derive(PartialEq)]
@@ -108,6 +111,8 @@ pub struct DiscoInfoResult {
     pub extensions: Vec<DataForm>,
 }
 
+impl IqResultPayload for DiscoInfoResult {}
+
 impl TryFrom<Element> for DiscoInfoResult {
     type Err = Error;
 
@@ -190,6 +195,8 @@ DiscoItemsQuery, "query", DISCO_ITEMS, [
     node: Option<String> = "node" => optional,
 ]);
 
+impl IqGetPayload for DiscoInfoResult {}
+
 generate_element_with_only_attributes!(
 /// Structure representing an `<item xmlns='http://jabber.org/protocol/disco#items'/>` element.
 Item, "item", DISCO_ITEMS, [
@@ -218,6 +225,8 @@ generate_element_with_children!(
     ]
 );
 
+impl IqResultPayload for DiscoItemsResult {}
+
 #[cfg(test)]
 mod tests {
     use super::*;

src/ibb.rs 🔗

@@ -5,6 +5,7 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 use helpers::Base64;
+use iq::IqSetPayload;
 
 generate_attribute!(Stanza, "stanza", {
     Iq => "iq",
@@ -17,6 +18,8 @@ generate_element_with_only_attributes!(Open, "open", IBB, [
     stanza: Stanza = "stanza" => default,
 ]);
 
+impl IqSetPayload for Open {}
+
 generate_element_with_text!(Data, "data", IBB,
     [
         seq: u16 = "seq" => required,
@@ -25,10 +28,14 @@ generate_element_with_text!(Data, "data", IBB,
     data: Base64<Vec<u8>>
 );
 
+impl IqSetPayload for Data {}
+
 generate_element_with_only_attributes!(Close, "close", IBB, [
     sid: String = "sid" => required,
 ]);
 
+impl IqSetPayload for Close {}
+
 #[cfg(test)]
 mod tests {
     use super::*;

src/ibr.rs 🔗

@@ -11,6 +11,7 @@ use minidom::Element;
 
 use error::Error;
 
+use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
 use data_forms::DataForm;
 
 use ns;
@@ -25,6 +26,10 @@ pub struct Query {
     //pub oob: Option<Oob>,
 }
 
+impl IqGetPayload for Query;
+impl IqSetPayload for Query;
+impl IqResultPayload for Query;
+
 impl TryFrom<Element> for Query {
     type Err = Error;
 

src/jingle.rs 🔗

@@ -12,6 +12,7 @@ use jid::Jid;
 
 use error::Error;
 use ns;
+use iq::IqSetPayload;
 
 generate_attribute!(Action, "action", {
     ContentAccept => "content-accept",
@@ -305,6 +306,8 @@ pub struct Jingle {
     pub other: Vec<Element>,
 }
 
+impl IqSetPayload for Jingle {}
+
 impl Jingle {
     pub fn new(action: Action, sid: SessionId) -> Jingle {
         Jingle {

src/mam.rs 🔗

@@ -11,6 +11,7 @@ use jid::Jid;
 
 use error::Error;
 
+use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
 use data_forms::DataForm;
 use rsm::Set;
 use forwarding::Forwarded;
@@ -25,6 +26,10 @@ pub struct Query {
     pub set: Option<Set>,
 }
 
+impl IqGetPayload for Query {}
+impl IqSetPayload for Query {}
+impl IqResultPayload for Query {}
+
 generate_element_with_children!(
     Result_, "result", MAM,
     attributes: [
@@ -42,6 +47,8 @@ pub struct Fin {
     pub set: Set,
 }
 
+impl IqResultPayload for Fin {}
+
 generate_attribute!(DefaultPrefs, "default", {
     Always => "always",
     Never => "never",
@@ -55,6 +62,10 @@ pub struct Prefs {
     pub never: Vec<Jid>,
 }
 
+impl IqGetPayload for Prefs {}
+impl IqSetPayload for Prefs {}
+impl IqResultPayload for Prefs {}
+
 impl TryFrom<Element> for Query {
     type Err = Error;
 

src/ping.rs 🔗

@@ -5,8 +5,12 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+use iq::IqGetPayload;
+
 generate_empty_element!(Ping, "ping", PING);
 
+impl IqGetPayload for Ping {}
+
 #[cfg(test)]
 mod tests {
     use super::*;

src/pubsub/pubsub.rs 🔗

@@ -15,6 +15,7 @@ use error::Error;
 
 use ns;
 
+use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
 use data_forms::DataForm;
 
 use pubsub::{NodeName, ItemId, Subscription, SubscriptionId};
@@ -364,6 +365,10 @@ pub enum PubSub {
     Unsubscribe(Unsubscribe),
 }
 
+impl IqGetPayload for PubSub {}
+impl IqSetPayload for PubSub {}
+impl IqResultPayload for PubSub {}
+
 impl TryFrom<Element> for PubSub {
     type Err = Error;
 

src/roster.rs 🔗

@@ -5,6 +5,7 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 use jid::Jid;
+use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
 
 generate_elem_id!(Group, "group", ROSTER);
 
@@ -54,6 +55,10 @@ generate_element_with_children!(
     ]
 );
 
+impl IqGetPayload for Roster {}
+impl IqSetPayload for Roster {}
+impl IqResultPayload for Roster {}
+
 #[cfg(test)]
 mod tests {
     use super::*;

src/version.rs 🔗

@@ -8,6 +8,7 @@ use try_from::TryFrom;
 use minidom::Element;
 use error::Error;
 use ns;
+use iq::{IqGetPayload, IqResultPayload};
 
 #[derive(Debug, Clone)]
 pub struct Version {
@@ -16,6 +17,9 @@ pub struct Version {
     pub os: Option<String>,
 }
 
+impl IqGetPayload for Version {}
+impl IqResultPayload for Version {}
+
 impl TryFrom<Element> for Version {
     type Err = Error;