macros: Merge generate_element_with_children!() into generate_element!().

This commit is contained in:
Emmanuel Gil Peyrot 2018-05-28 16:45:13 +02:00
parent 9c598fbdf9
commit 3fb99988d5
13 changed files with 28 additions and 31 deletions

View file

@ -212,7 +212,7 @@ attributes: [
name: Option<String> = "name" => optional, name: Option<String> = "name" => optional,
]); ]);
generate_element_with_children!( generate_element!(
/// Structure representing a `<query /// Structure representing a `<query
/// xmlns='http://jabber.org/protocol/disco#items'/>` element. /// xmlns='http://jabber.org/protocol/disco#items'/>` element.
/// ///

View file

@ -16,7 +16,7 @@ use sha3::{Sha3_256, Sha3_512};
use blake2::Blake2b; use blake2::Blake2b;
use digest::{Digest, VariableOutput}; use digest::{Digest, VariableOutput};
generate_element_with_children!( generate_element!(
ECaps2, "c", ECAPS2, ECaps2, "c", ECAPS2,
children: [ children: [
hashes: Vec<Hash> = ("hash", HASHES) => Hash hashes: Vec<Hash> = ("hash", HASHES) => Hash

View file

@ -66,7 +66,7 @@ generate_attribute!(Disposition, "disposition", {
generate_id!(ContentId); generate_id!(ContentId);
generate_element_with_children!( generate_element!(
Content, "content", JINGLE, Content, "content", JINGLE,
attributes: [ attributes: [
creator: Creator = "creator" => required, creator: Creator = "creator" => required,

View file

@ -18,7 +18,7 @@ use minidom::Element;
use error::Error; use error::Error;
use ns; use ns;
generate_element_with_children!( generate_element!(
#[derive(PartialEq, Default)] #[derive(PartialEq, Default)]
Range, "range", JINGLE_FT, Range, "range", JINGLE_FT,
attributes: [ attributes: [

View file

@ -466,19 +466,16 @@ macro_rules! generate_serialiser {
macro_rules! generate_element { 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),+,]) => ( ($(#[$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: []); generate_element!($(#[$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),+]) => ( ($(#[$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: []); generate_element!($(#[$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),*]) => ( ($(#[$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),*]); generate_element!($(#[$meta])* $elem, $name, $ns, attributes: [], children: [$($(#[$child_meta])* $child_ident: $coucou<$child_type> = ($child_name, $child_ns) => $child_constructor),*]);
); );
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),*,], children: [$($(#[$child_meta:meta])* $child_ident:ident: $coucou:tt<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),*]) => ( ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),*,], 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: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: [$($(#[$child_meta])* $child_ident: $coucou<$child_type> = ($child_name, $child_ns) => $child_constructor),*]); generate_element!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: [$($(#[$child_meta])* $child_ident: $coucou<$child_type> = ($child_name, $child_ns) => $child_constructor),*]);
); );
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),*], children: [$($(#[$child_meta:meta])* $child_ident:ident: $coucou:tt<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),*]) => ( ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),*], children: [$($(#[$child_meta:meta])* $child_ident:ident: $coucou:tt<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),*]) => (
$(#[$meta])* $(#[$meta])*

View file

@ -18,7 +18,7 @@ use forwarding::Forwarded;
use ns; use ns;
generate_element_with_children!( generate_element!(
Query, "query", MAM, Query, "query", MAM,
attributes: [ attributes: [
queryid: Option<String> = "queryid" => optional, queryid: Option<String> = "queryid" => optional,
@ -34,7 +34,7 @@ impl IqGetPayload for Query {}
impl IqSetPayload for Query {} impl IqSetPayload for Query {}
impl IqResultPayload for Query {} impl IqResultPayload for Query {}
generate_element_with_children!( generate_element!(
Result_, "result", MAM, Result_, "result", MAM,
attributes: [ attributes: [
id: String = "id" => required, id: String = "id" => required,
@ -49,7 +49,7 @@ generate_attribute!(
Complete, "complete", bool Complete, "complete", bool
); );
generate_element_with_children!( generate_element!(
Fin, "fin", MAM, Fin, "fin", MAM,
attributes: [ attributes: [
complete: Complete = "complete" => default complete: Complete = "complete" => default

View file

@ -13,7 +13,7 @@ generate_element_with_text!(URI, "uri", MEDIA_ELEMENT,
uri: TrimmedPlainText<String> uri: TrimmedPlainText<String>
); );
generate_element_with_children!(MediaElement, "media", MEDIA_ELEMENT, generate_element!(MediaElement, "media", MEDIA_ELEMENT,
attributes: [ attributes: [
width: Option<usize> = "width" => optional, width: Option<usize> = "width" => optional,
height: Option<usize> = "height" => optional height: Option<usize> = "height" => optional

View file

@ -5,7 +5,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
generate_element_with_children!( generate_element!(
Muc, "x", MUC, children: [ Muc, "x", MUC, children: [
password: Option<String> = ("password", MUC) => String password: Option<String> = ("password", MUC) => String
] ]

View file

@ -142,7 +142,7 @@ generate_attribute!(Role, "role", {
None => "none", None => "none",
}, Default = None); }, Default = None);
generate_element_with_children!( generate_element!(
Item, "item", MUC_USER, attributes: [ Item, "item", MUC_USER, attributes: [
affiliation: Affiliation = "affiliation" => required, affiliation: Affiliation = "affiliation" => required,
jid: Option<Jid> = "jid" => optional, jid: Option<Jid> = "jid" => optional,
@ -155,7 +155,7 @@ generate_element_with_children!(
] ]
); );
generate_element_with_children!( generate_element!(
MucUser, "x", MUC_USER, children: [ MucUser, "x", MUC_USER, children: [
status: Vec<Status> = ("status", MUC_USER) => Status, status: Vec<Status> = ("status", MUC_USER) => Status,
items: Vec<Item> = ("item", MUC_USER) => Item items: Vec<Item> = ("item", MUC_USER) => Item

View file

@ -22,7 +22,7 @@ use pubsub::{NodeName, ItemId, Subscription, SubscriptionId};
// TODO: a better solution would be to split this into a query and a result elements, like for // TODO: a better solution would be to split this into a query and a result elements, like for
// XEP-0030. // XEP-0030.
generate_element_with_children!( generate_element!(
/// A list of affiliations you have on a service, or on a node. /// A list of affiliations you have on a service, or on a node.
Affiliations, "affiliations", PUBSUB, Affiliations, "affiliations", PUBSUB,
attributes: [ attributes: [
@ -70,7 +70,7 @@ generate_element!(
] ]
); );
generate_element_with_children!( generate_element!(
/// Request to configure a new node. /// Request to configure a new node.
Configure, "configure", PUBSUB, Configure, "configure", PUBSUB,
children: [ children: [
@ -100,7 +100,7 @@ generate_element!(
] ]
); );
generate_element_with_children!( generate_element!(
/// A request for a list of items. /// A request for a list of items.
Items, "items", PUBSUB, Items, "items", PUBSUB,
attributes: [ attributes: [
@ -158,7 +158,7 @@ impl From<Item> for Element {
} }
} }
generate_element_with_children!( generate_element!(
/// The options associated to a subscription request. /// The options associated to a subscription request.
Options, "options", PUBSUB, Options, "options", PUBSUB,
attributes: [ attributes: [
@ -177,7 +177,7 @@ generate_element_with_children!(
] ]
); );
generate_element_with_children!( generate_element!(
/// Request to publish items to a node. /// Request to publish items to a node.
Publish, "publish", PUBSUB, Publish, "publish", PUBSUB,
attributes: [ attributes: [
@ -190,7 +190,7 @@ generate_element_with_children!(
] ]
); );
generate_element_with_children!( generate_element!(
/// The options associated to a publish request. /// The options associated to a publish request.
PublishOptions, "publish-options", PUBSUB, PublishOptions, "publish-options", PUBSUB,
children: [ children: [
@ -204,7 +204,7 @@ generate_attribute!(
Notify, "notify", bool Notify, "notify", bool
); );
generate_element_with_children!( generate_element!(
/// A request to retract some items from a node. /// A request to retract some items from a node.
Retract, "retract", PUBSUB, Retract, "retract", PUBSUB,
attributes: [ attributes: [
@ -275,7 +275,7 @@ generate_element!(
] ]
); );
generate_element_with_children!( generate_element!(
/// A request for current subscriptions. /// A request for current subscriptions.
Subscriptions, "subscriptions", PUBSUB, Subscriptions, "subscriptions", PUBSUB,
attributes: [ attributes: [
@ -288,7 +288,7 @@ generate_element_with_children!(
] ]
); );
generate_element_with_children!( generate_element!(
/// A subscription element, describing the state of a subscription. /// A subscription element, describing the state of a subscription.
SubscriptionElem, "subscription", PUBSUB, SubscriptionElem, "subscription", PUBSUB,
attributes: [ attributes: [

View file

@ -17,7 +17,7 @@ generate_attribute!(Subscription, "subscription", {
Remove => "remove", Remove => "remove",
}, Default = None); }, Default = None);
generate_element_with_children!( generate_element!(
/// Contact from the users contact list. /// Contact from the users contact list.
#[derive(PartialEq)] #[derive(PartialEq)]
Item, "item", ROSTER, Item, "item", ROSTER,
@ -38,7 +38,7 @@ generate_element_with_children!(
] ]
); );
generate_element_with_children!( generate_element!(
/// The contact list of the user. /// The contact list of the user.
Roster, "query", ROSTER, Roster, "query", ROSTER,
attributes: [ attributes: [

View file

@ -60,7 +60,7 @@ generate_element!(
] ]
); );
generate_element_with_children!( generate_element!(
Failed, "failed", SM, Failed, "failed", SM,
attributes: [ attributes: [
h: Option<u32> = "h" => optional, h: Option<u32> = "h" => optional,

View file

@ -6,7 +6,7 @@
use iq::{IqGetPayload, IqResultPayload}; use iq::{IqGetPayload, IqResultPayload};
generate_element_with_children!( generate_element!(
Version, "query", VERSION, Version, "query", VERSION,
children: [ children: [
name: Required<String> = ("name", VERSION) => String, name: Required<String> = ("name", VERSION) => String,