macros: Rename generate_element_with_only_attributes!() into generate_element!().

Emmanuel Gil Peyrot created

Change summary

src/disco.rs           | 20 ++++++++++++--------
src/eme.rs             |  5 +++--
src/ibb.rs             |  6 ++++--
src/idle.rs            |  3 ++-
src/jingle_ft.rs       |  3 ++-
src/jingle_ibb.rs      |  3 ++-
src/jingle_s5b.rs      |  3 ++-
src/macros.rs          | 18 +++++++++---------
src/message_correct.rs |  3 ++-
src/muc/user.rs        |  3 ++-
src/pubsub/pubsub.rs   | 25 +++++++++++++++----------
src/receipts.rs        |  3 ++-
src/sm.rs              | 25 +++++++++++++++----------
src/stanza_id.rs       |  6 ++++--
src/stream.rs          |  3 ++-
src/websocket.rs       |  3 ++-
16 files changed, 80 insertions(+), 52 deletions(-)

Detailed changes

src/disco.rs 🔗

@@ -17,22 +17,24 @@ use ns;
 use iq::{IqGetPayload, IqResultPayload};
 use data_forms::{DataForm, DataFormType};
 
-generate_element_with_only_attributes!(
+generate_element!(
 /// Structure representing a `<query xmlns='http://jabber.org/protocol/disco#info'/>` element.
 ///
 /// It should only be used in an `<iq type='get'/>`, as it can only represent
 /// the request, and not a result.
-DiscoInfoQuery, "query", DISCO_INFO, [
+DiscoInfoQuery, "query", DISCO_INFO,
+attributes: [
     /// Node on which we are doing the discovery.
     node: Option<String> = "node" => optional,
 ]);
 
 impl IqGetPayload for DiscoInfoQuery {}
 
-generate_element_with_only_attributes!(
+generate_element!(
 /// Structure representing a `<feature xmlns='http://jabber.org/protocol/disco#info'/>` element.
 #[derive(PartialEq)]
-Feature, "feature", DISCO_INFO, [
+Feature, "feature", DISCO_INFO,
+attributes: [
     /// Namespace of the feature we want to represent.
     var: String = "var" => required,
 ]);
@@ -185,21 +187,23 @@ impl From<DiscoInfoResult> for Element {
     }
 }
 
-generate_element_with_only_attributes!(
+generate_element!(
 /// Structure representing a `<query xmlns='http://jabber.org/protocol/disco#items'/>` element.
 ///
 /// It should only be used in an `<iq type='get'/>`, as it can only represent
 /// the request, and not a result.
-DiscoItemsQuery, "query", DISCO_ITEMS, [
+DiscoItemsQuery, "query", DISCO_ITEMS,
+attributes: [
     /// Node on which we are doing the discovery.
     node: Option<String> = "node" => optional,
 ]);
 
 impl IqGetPayload for DiscoItemsQuery {}
 
-generate_element_with_only_attributes!(
+generate_element!(
 /// Structure representing an `<item xmlns='http://jabber.org/protocol/disco#items'/>` element.
-Item, "item", DISCO_ITEMS, [
+Item, "item", DISCO_ITEMS,
+attributes: [
     /// JID of the entity pointed by this item.
     jid: Jid = "jid" => required,
     /// Node of the entity pointed by this item.

src/eme.rs 🔗

@@ -4,9 +4,10 @@
 // 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/.
 
-generate_element_with_only_attributes!(
+generate_element!(
 /// Structure representing an `<encryption xmlns='urn:xmpp:eme:0'/>` element.
-ExplicitMessageEncryption, "encryption", EME, [
+ExplicitMessageEncryption, "encryption", EME,
+attributes: [
     /// Namespace of the encryption scheme used.
     namespace: String = "namespace" => required,
 

src/ibb.rs 🔗

@@ -12,7 +12,8 @@ generate_attribute!(Stanza, "stanza", {
     Message => "message",
 }, Default = Iq);
 
-generate_element_with_only_attributes!(Open, "open", IBB, [
+generate_element!(Open, "open", IBB,
+attributes: [
     block_size: u16 = "block-size" => required,
     sid: String = "sid" => required,
     stanza: Stanza = "stanza" => default,
@@ -30,7 +31,8 @@ generate_element_with_text!(Data, "data", IBB,
 
 impl IqSetPayload for Data {}
 
-generate_element_with_only_attributes!(Close, "close", IBB, [
+generate_element!(Close, "close", IBB,
+attributes: [
     sid: String = "sid" => required,
 ]);
 

src/idle.rs 🔗

@@ -6,7 +6,8 @@
 
 use date::DateTime;
 
-generate_element_with_only_attributes!(Idle, "idle", IDLE, [
+generate_element!(Idle, "idle", IDLE,
+attributes: [
     since: DateTime = "since" => required,
 ]);
 

src/jingle_ft.rs 🔗

@@ -287,7 +287,8 @@ impl From<Checksum> for Element {
     }
 }
 
-generate_element_with_only_attributes!(Received, "received", JINGLE_FT, [
+generate_element!(Received, "received", JINGLE_FT,
+attributes: [
     name: ContentId = "name" => required,
     creator: Creator = "creator" => required,
 ]);

src/jingle_ibb.rs 🔗

@@ -8,7 +8,8 @@ use ibb::Stanza;
 
 generate_id!(StreamId);
 
-generate_element_with_only_attributes!(Transport, "transport", JINGLE_IBB, [
+generate_element!(Transport, "transport", JINGLE_IBB,
+attributes: [
     block_size: u16 = "block-size" => required,
     sid: StreamId = "sid" => required,
     stanza: Stanza = "stanza" => default,

src/jingle_s5b.rs 🔗

@@ -30,7 +30,8 @@ generate_id!(CandidateId);
 
 generate_id!(StreamId);
 
-generate_element_with_only_attributes!(Candidate, "candidate", JINGLE_S5B, [
+generate_element!(Candidate, "candidate", JINGLE_S5B,
+attributes: [
     cid: CandidateId = "cid" => required,
     host: IpAddr = "host" => required,
     jid: Jid = "jid" => required,

src/macros.rs 🔗

@@ -285,15 +285,6 @@ macro_rules! generate_empty_element {
     );
 }
 
-macro_rules! generate_element_with_only_attributes {
-    ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+,]) => (
-        generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: []);
-    );
-    ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+]) => (
-        generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: []);
-    );
-}
-
 macro_rules! generate_id {
     ($elem:ident) => (
         #[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -473,6 +464,15 @@ macro_rules! generate_serialiser {
     );
 }
 
+macro_rules! generate_element {
+    ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+,]) => (
+        generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: []);
+    );
+    ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+]) => (
+        generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: []);
+    );
+}
+
 macro_rules! generate_element_with_children {
     ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, children: [$($(#[$child_meta:meta])* $child_ident:ident: $coucou:tt<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),*]) => (
         generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [], children: [$($(#[$child_meta])* $child_ident: $coucou<$child_type> = ($child_name, $child_ns) => $child_constructor),*]);

src/message_correct.rs 🔗

@@ -4,7 +4,8 @@
 // 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/.
 
-generate_element_with_only_attributes!(Replace, "replace", MESSAGE_CORRECT, [
+generate_element!(Replace, "replace", MESSAGE_CORRECT,
+attributes: [
     id: String = "id" => required,
 ]);
 

src/muc/user.rs 🔗

@@ -120,7 +120,8 @@ impl From<Actor> for Element {
     }
 }
 
-generate_element_with_only_attributes!(Continue, "continue", MUC_USER, [
+generate_element!(Continue, "continue", MUC_USER,
+attributes: [
     thread: Option<String> = "thread" => optional,
 ]);
 

src/pubsub/pubsub.rs 🔗

@@ -58,9 +58,10 @@ generate_attribute!(
     }
 );
 
-generate_element_with_only_attributes!(
+generate_element!(
     /// An affiliation element.
-    Affiliation, "affiliation", PUBSUB, [
+    Affiliation, "affiliation", PUBSUB,
+    attributes: [
         /// The node this affiliation pertains to.
         node: NodeName = "node" => required,
 
@@ -78,17 +79,19 @@ generate_element_with_children!(
     ]
 );
 
-generate_element_with_only_attributes!(
+generate_element!(
     /// Request to create a new node.
-    Create, "create", PUBSUB, [
+    Create, "create", PUBSUB,
+    attributes: [
         /// The node name to create, if `None` the service will generate one.
         node: Option<NodeName> = "node" => optional,
     ]
 );
 
-generate_element_with_only_attributes!(
+generate_element!(
     /// Request for a default node configuration.
-    Default, "default", PUBSUB, [
+    Default, "default", PUBSUB,
+    attributes: [
         /// The node targetted by this request, otherwise the entire service.
         node: Option<NodeName> = "node" => optional,
 
@@ -260,9 +263,10 @@ impl From<SubscribeOptions> for Element {
     }
 }
 
-generate_element_with_only_attributes!(
+generate_element!(
     /// A request to subscribe a JID to a node.
-    Subscribe, "subscribe", PUBSUB, [
+    Subscribe, "subscribe", PUBSUB,
+    attributes: [
         /// The JID being subscribed.
         jid: Jid = "jid" => required,
 
@@ -306,9 +310,10 @@ generate_element_with_children!(
     ]
 );
 
-generate_element_with_only_attributes!(
+generate_element!(
     /// An unsubscribe request.
-    Unsubscribe, "unsubscribe", PUBSUB, [
+    Unsubscribe, "unsubscribe", PUBSUB,
+    attributes: [
         /// The JID affected by this request.
         jid: Jid = "jid" => required,
 

src/receipts.rs 🔗

@@ -6,7 +6,8 @@
 
 generate_empty_element!(Request, "request", RECEIPTS);
 
-generate_element_with_only_attributes!(Received, "received", RECEIPTS, [
+generate_element!(Received, "received", RECEIPTS,
+attributes: [
     id: Option<String> = "id" => optional,
 ]);
 

src/sm.rs 🔗

@@ -6,8 +6,9 @@
 
 use stanza_error::DefinedCondition;
 
-generate_element_with_only_attributes!(
-    A, "a", SM, [
+generate_element!(
+    A, "a", SM,
+    attributes: [
         h: u32 = "h" => required,
     ]
 );
@@ -20,8 +21,9 @@ impl A {
 
 generate_attribute!(ResumeAttr, "resume", bool);
 
-generate_element_with_only_attributes!(
-    Enable, "enable", SM, [
+generate_element!(
+    Enable, "enable", SM,
+    attributes: [
         // TODO: should be the infinite integer set ≥ 1.
         max: Option<u32> = "max" => optional,
         resume: ResumeAttr = "resume" => default,
@@ -47,8 +49,9 @@ impl Enable {
     }
 }
 
-generate_element_with_only_attributes!(
-    Enabled, "enabled", SM, [
+generate_element!(
+    Enabled, "enabled", SM,
+    attributes: [
         id: Option<String> = "id" => optional,
         location: Option<String> = "location" => optional,
         // TODO: should be the infinite integer set ≥ 1.
@@ -72,15 +75,17 @@ generate_empty_element!(
     R, "r", SM
 );
 
-generate_element_with_only_attributes!(
-    Resume, "resume", SM, [
+generate_element!(
+    Resume, "resume", SM,
+    attributes: [
         h: u32 = "h" => required,
         previd: String = "previd" => required,
     ]
 );
 
-generate_element_with_only_attributes!(
-    Resumed, "resumed", SM, [
+generate_element!(
+    Resumed, "resumed", SM,
+    attributes: [
         h: u32 = "h" => required,
         previd: String = "previd" => required,
     ]

src/stanza_id.rs 🔗

@@ -6,12 +6,14 @@
 
 use jid::Jid;
 
-generate_element_with_only_attributes!(StanzaId, "stanza-id", SID, [
+generate_element!(StanzaId, "stanza-id", SID,
+attributes: [
     id: String = "id" => required,
     by: Jid = "by" => required,
 ]);
 
-generate_element_with_only_attributes!(OriginId, "origin-id", SID, [
+generate_element!(OriginId, "origin-id", SID,
+attributes: [
     id: String = "id" => required,
 ]);
 

src/stream.rs 🔗

@@ -6,7 +6,8 @@
 
 use jid::Jid;
 
-generate_element_with_only_attributes!(Stream, "stream", STREAM, [
+generate_element!(Stream, "stream", STREAM,
+attributes: [
     from: Option<Jid> = "from" => optional,
     to: Option<Jid> = "to" => optional,
     id: Option<String> = "id" => optional,

src/websocket.rs 🔗

@@ -6,7 +6,8 @@
 
 use jid::Jid;
 
-generate_element_with_only_attributes!(Open, "open", WEBSOCKET, [
+generate_element!(Open, "open", WEBSOCKET,
+attributes: [
     from: Option<Jid> = "from" => optional,
     to: Option<Jid> = "to" => optional,
     id: Option<String> = "id" => optional,