diff --git a/src/disco.rs b/src/disco.rs
index 4c70edd2..679b06e5 100644
--- a/src/disco.rs
+++ b/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 `` element.
///
/// It should only be used in an ``, 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 = "node" => optional,
]);
impl IqGetPayload for DiscoInfoQuery {}
-generate_element_with_only_attributes!(
+generate_element!(
/// Structure representing a `` 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 for Element {
}
}
-generate_element_with_only_attributes!(
+generate_element!(
/// Structure representing a `` element.
///
/// It should only be used in an ``, 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 = "node" => optional,
]);
impl IqGetPayload for DiscoItemsQuery {}
-generate_element_with_only_attributes!(
+generate_element!(
/// Structure representing an ` ` 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.
diff --git a/src/eme.rs b/src/eme.rs
index ff3737b0..a276ba25 100644
--- a/src/eme.rs
+++ b/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 `` element.
-ExplicitMessageEncryption, "encryption", EME, [
+ExplicitMessageEncryption, "encryption", EME,
+attributes: [
/// Namespace of the encryption scheme used.
namespace: String = "namespace" => required,
diff --git a/src/ibb.rs b/src/ibb.rs
index e33ca3bf..2edb8ee5 100644
--- a/src/ibb.rs
+++ b/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,
]);
diff --git a/src/idle.rs b/src/idle.rs
index 1312efb9..22e84460 100644
--- a/src/idle.rs
+++ b/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,
]);
diff --git a/src/jingle_ft.rs b/src/jingle_ft.rs
index eb7e9169..b9e1d3ef 100644
--- a/src/jingle_ft.rs
+++ b/src/jingle_ft.rs
@@ -287,7 +287,8 @@ impl From 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,
]);
diff --git a/src/jingle_ibb.rs b/src/jingle_ibb.rs
index 2e68e685..156ba4d3 100644
--- a/src/jingle_ibb.rs
+++ b/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,
diff --git a/src/jingle_s5b.rs b/src/jingle_s5b.rs
index fe9eaa10..94f3c0c7 100644
--- a/src/jingle_s5b.rs
+++ b/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,
diff --git a/src/macros.rs b/src/macros.rs
index 3c07f180..9b950104 100644
--- a/src/macros.rs
+++ b/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),*]);
diff --git a/src/message_correct.rs b/src/message_correct.rs
index 3dbb86e4..f3019797 100644
--- a/src/message_correct.rs
+++ b/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,
]);
diff --git a/src/muc/user.rs b/src/muc/user.rs
index 69060cef..15cea9e4 100644
--- a/src/muc/user.rs
+++ b/src/muc/user.rs
@@ -120,7 +120,8 @@ impl From for Element {
}
}
-generate_element_with_only_attributes!(Continue, "continue", MUC_USER, [
+generate_element!(Continue, "continue", MUC_USER,
+attributes: [
thread: Option = "thread" => optional,
]);
diff --git a/src/pubsub/pubsub.rs b/src/pubsub/pubsub.rs
index 840232b0..807ce908 100644
--- a/src/pubsub/pubsub.rs
+++ b/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 = "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 = "node" => optional,
@@ -260,9 +263,10 @@ impl From 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,
diff --git a/src/receipts.rs b/src/receipts.rs
index dfaf5473..a557d008 100644
--- a/src/receipts.rs
+++ b/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 = "id" => optional,
]);
diff --git a/src/sm.rs b/src/sm.rs
index 4030bf71..3558c8e7 100644
--- a/src/sm.rs
+++ b/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 = "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 = "id" => optional,
location: Option = "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,
]
diff --git a/src/stanza_id.rs b/src/stanza_id.rs
index b321b46c..16a8d9fc 100644
--- a/src/stanza_id.rs
+++ b/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,
]);
diff --git a/src/stream.rs b/src/stream.rs
index 93a71c41..aa48ad9f 100644
--- a/src/stream.rs
+++ b/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 = "from" => optional,
to: Option = "to" => optional,
id: Option = "id" => optional,
diff --git a/src/websocket.rs b/src/websocket.rs
index b5aa7903..78d0cada 100644
--- a/src/websocket.rs
+++ b/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 = "from" => optional,
to: Option = "to" => optional,
id: Option = "id" => optional,