diff --git a/src/avatar.rs b/src/avatar.rs index 48893e4c55ce34762ac735548e9fe087221d281e..6e2d3ce03da49f5891ef45fa28050f1ddd9b47d8 100644 --- a/src/avatar.rs +++ b/src/avatar.rs @@ -24,22 +24,22 @@ generate_element!( Info, "info", AVATAR_METADATA, attributes: [ /// The size of the image data in bytes. - bytes: u16 = "bytes" => required, + bytes: Required = "bytes", /// The width of the image in pixels. - width: Option = "width" => optional, + width: Option = "width", /// The height of the image in pixels. - height: Option = "height" => optional, + height: Option = "height", /// The SHA-1 hash of the image data for the specified content-type. - id: Sha1HexAttribute = "id" => required, + id: Required = "id", /// The IANA-registered content type of the image data. - type_: String = "type" => required, + type_: Required = "type", /// The http: or https: URL at which the image data file is hosted. - url: Option = "url" => optional, + url: Option = "url", ] ); diff --git a/src/bookmarks.rs b/src/bookmarks.rs index 273f770875d538ebbbfc4f254a4a379d304fd89e..b1c59b0e40d0372921eeb082ac29caa42d4c1116 100644 --- a/src/bookmarks.rs +++ b/src/bookmarks.rs @@ -18,13 +18,13 @@ generate_element!( Conference, "conference", BOOKMARKS, attributes: [ /// Whether a conference bookmark should be joined automatically. - autojoin: Autojoin = "autojoin" => default, + autojoin: Default = "autojoin", /// The JID of the conference. - jid: Jid = "jid" => required, + jid: Required = "jid", /// A user-defined name for this conference. - name: String = "name" => required + name: Required = "name", ], children: [ /// The nick the user will use to join this conference. @@ -40,10 +40,10 @@ generate_element!( Url, "url", BOOKMARKS, attributes: [ /// A user-defined name for this URL. - name: String = "name" => required, + name: Required = "name", /// The URL of this bookmark. - url: String = "url" => required + url: Required = "url", ] ); diff --git a/src/data_forms.rs b/src/data_forms.rs index 6e2d4e3d2c770198860c6dba11b6043e11a16572..9a1ed3e3297556ebd26cabe8be938fb64b97c8f7 100644 --- a/src/data_forms.rs +++ b/src/data_forms.rs @@ -15,7 +15,7 @@ generate_element!( Option_, "option", DATA_FORMS, attributes: [ /// The optional label to be displayed to the user for this option. - label: Option = "label" => optional + label: Option = "label" ], children: [ /// The value returned to the server when selecting this option. diff --git a/src/delay.rs b/src/delay.rs index a02b44b1a4338929806b75529c2af166cb945191..80f92edd00eb8b8023d8920df551de550493bed8 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -15,10 +15,10 @@ generate_element!( Delay, "delay", DELAY, attributes: [ /// The entity which delayed this message. - from: Option = "from" => optional, + from: Option = "from", /// The time at which this message got stored. - stamp: DateTime = "stamp" => required + stamp: Required = "stamp" ], text: ( /// The optional reason this message got delayed. diff --git a/src/disco.rs b/src/disco.rs index 9f72cec56677c7d072657a43a093d250f248940d..43c15903365dc900188ac0acc2801cc24ed2a1de 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -20,7 +20,7 @@ generate_element!( DiscoInfoQuery, "query", DISCO_INFO, attributes: [ /// Node on which we are doing the discovery. - node: Option = "node" => optional, + node: Option = "node", ]); impl IqGetPayload for DiscoInfoQuery {} @@ -31,7 +31,7 @@ generate_element!( Feature, "feature", DISCO_INFO, attributes: [ /// Namespace of the feature we want to represent. - var: String = "var" => required, + var: Required = "var", ]); impl Feature { @@ -206,7 +206,7 @@ generate_element!( DiscoItemsQuery, "query", DISCO_ITEMS, attributes: [ /// Node on which we are doing the discovery. - node: Option = "node" => optional, + node: Option = "node", ]); impl IqGetPayload for DiscoItemsQuery {} @@ -216,11 +216,11 @@ generate_element!( Item, "item", DISCO_ITEMS, attributes: [ /// JID of the entity pointed by this item. - jid: Jid = "jid" => required, + jid: Required = "jid", /// Node of the entity pointed by this item. - node: Option = "node" => optional, + node: Option = "node", /// Name of the entity pointed by this item. - name: Option = "name" => optional, + name: Option = "name", ]); generate_element!( @@ -232,7 +232,7 @@ generate_element!( DiscoItemsResult, "query", DISCO_ITEMS, attributes: [ /// Node on which we have done this discovery. - node: Option = "node" => optional + node: Option = "node" ], children: [ /// List of items pointed by this entity. diff --git a/src/eme.rs b/src/eme.rs index cd24e43d03b7bf95799d75b86b086d3b280d8ab1..20623ff2f2b628ed56310bb8d1110d6df20ead6d 100644 --- a/src/eme.rs +++ b/src/eme.rs @@ -11,11 +11,11 @@ generate_element!( ExplicitMessageEncryption, "encryption", EME, attributes: [ /// Namespace of the encryption scheme used. - namespace: String = "namespace" => required, + namespace: Required = "namespace", /// User-friendly name for the encryption scheme, should be `None` for OTR, /// legacy OpenPGP and OX. - name: Option = "name" => optional, + name: Option = "name", ] ); diff --git a/src/hashes.rs b/src/hashes.rs index d6a1f37baf3609a24a5ff68a84b837c1b0e4ea4d..c097d034690678a682b1dd9a73daa72a85e1657c 100644 --- a/src/hashes.rs +++ b/src/hashes.rs @@ -102,7 +102,7 @@ generate_element!( Hash, "hash", HASHES, attributes: [ /// The algorithm used to create this hash. - algo: Algo = "algo" => required + algo: Required = "algo" ], text: ( /// The hash value, as a vector of bytes. diff --git a/src/ibb.rs b/src/ibb.rs index 960761187becc66ba7d9e1f7dd2ec02922d635ba..aa1e07d3c2308cd767defbec47be9e80d72f3fd9 100644 --- a/src/ibb.rs +++ b/src/ibb.rs @@ -30,13 +30,13 @@ generate_element!( Open, "open", IBB, attributes: [ /// Maximum size in bytes for each chunk. - block_size: u16 = "block-size" => required, + block_size: Required = "block-size", /// The identifier to be used to create a stream. - sid: StreamId = "sid" => required, + sid: Required = "sid", /// Which stanza type to use to exchange data. - stanza: Stanza = "stanza" => default, + stanza: Default = "stanza", ]); impl IqSetPayload for Open {} @@ -46,10 +46,10 @@ generate_element!( Data, "data", IBB, attributes: [ /// Sequence number of this chunk, must wraparound after 65535. - seq: u16 = "seq" => required, + seq: Required = "seq", /// The identifier of the stream on which data is being exchanged. - sid: StreamId = "sid" => required + sid: Required = "sid" ], text: ( /// Vector of bytes to be exchanged. @@ -64,7 +64,7 @@ generate_element!( Close, "close", IBB, attributes: [ /// The identifier of the stream to be closed. - sid: StreamId = "sid" => required, + sid: Required = "sid", ]); impl IqSetPayload for Close {} diff --git a/src/idle.rs b/src/idle.rs index bbf3f15114546636f20c49de18edec939d15ce8e..89b62c0549f139c4832ea5feafbf9dc77efbe5e3 100644 --- a/src/idle.rs +++ b/src/idle.rs @@ -12,7 +12,7 @@ generate_element!( Idle, "idle", IDLE, attributes: [ /// The time at which the user stopped interacting. - since: DateTime = "since" => required, + since: Required = "since", ] ); diff --git a/src/jingle.rs b/src/jingle.rs index 2596687218cca28b0f0c6a0cc4ba16bbc3dc19a4..b891ab7caea1b7a2d7fbae352fd8ade108b645b4 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -169,16 +169,16 @@ generate_element!( Content, "content", JINGLE, attributes: [ /// Who created this content. - creator: Creator = "creator" => required, + creator: Required = "creator", /// How the content definition is to be interpreted by the recipient. - disposition: Disposition = "disposition" => default, + disposition: Default = "disposition", /// A per-session unique identifier for this content. - name: ContentId = "name" => required, + name: Required = "name", /// Who can send data for this content. - senders: Senders = "senders" => default + senders: Default = "senders", ], children: [ /// What to send. diff --git a/src/jingle_ft.rs b/src/jingle_ft.rs index 2d61569cb6209bccfed5e75d5a0e1a013614dccb..67c055e23290eed991eb0a0add4a68761c123ccc 100644 --- a/src/jingle_ft.rs +++ b/src/jingle_ft.rs @@ -20,11 +20,11 @@ generate_element!( Range, "range", JINGLE_FT, attributes: [ /// The offset in bytes from the beginning of the file. - offset: u64 = "offset" => default, + offset: Default = "offset", /// The length in bytes of the range, or None to be the entire /// remaining of the file. - length: Option = "length" => optional + length: Option = "length" ], children: [ /// List of hashes for this range. @@ -344,10 +344,10 @@ generate_element!( Received, "received", JINGLE_FT, attributes: [ /// The content identifier of this Jingle session. - name: ContentId = "name" => required, + name: Required = "name", /// The creator of this file transfer. - creator: Creator = "creator" => required, + creator: Required = "creator", ] ); diff --git a/src/jingle_ibb.rs b/src/jingle_ibb.rs index 08370e1f7f9dd328abb9dd3c2194547c20422111..019f03429f520c8983b1f937b96ba4bf8b68a3e5 100644 --- a/src/jingle_ibb.rs +++ b/src/jingle_ibb.rs @@ -12,13 +12,13 @@ generate_element!( Transport, "transport", JINGLE_IBB, attributes: [ /// Maximum size in bytes for each chunk. - block_size: u16 = "block-size" => required, + block_size: Required = "block-size", /// The identifier to be used to create a stream. - sid: StreamId = "sid" => required, + sid: Required = "sid", /// Which stanza type to use to exchange data. - stanza: Stanza = "stanza" => default, + stanza: Default = "stanza", ]); #[cfg(test)] diff --git a/src/jingle_s5b.rs b/src/jingle_s5b.rs index 613842f900ca1b8d9179d6f675945a62aa24f600..1f3a3ee60fb3b7f67c3cbc472bd00237a333fe6e 100644 --- a/src/jingle_s5b.rs +++ b/src/jingle_s5b.rs @@ -55,23 +55,23 @@ generate_element!( Candidate, "candidate", JINGLE_S5B, attributes: [ /// The identifier for this candidate. - cid: CandidateId = "cid" => required, + cid: Required = "cid", /// The host to connect to. - host: IpAddr = "host" => required, + host: Required = "host", /// The JID to request at the given end. - jid: Jid = "jid" => required, + jid: Required = "jid", /// The port to connect to. - port: Option = "port" => optional, + port: Option = "port", /// The priority of this candidate, computed using this formula: /// priority = (2^16)*(type preference) + (local preference) - priority: u32 = "priority" => required, + priority: Required = "priority", /// The type of the connection being proposed by this candidate. - type_: Type = "type" => default, + type_: Default = "type", ] ); diff --git a/src/mam.rs b/src/mam.rs index 453b4f606deeafbf321d58867e27564969f7e94f..b68dabb272b8052bd173da25e7cb40fa38af7950 100644 --- a/src/mam.rs +++ b/src/mam.rs @@ -27,10 +27,10 @@ generate_element!( attributes: [ /// An optional identifier for matching forwarded messages to this /// query. - queryid: Option = "queryid" => optional, + queryid: Option = "queryid", /// Must be set to Some when querying a PubSub node’s archive. - node: Option = "node" => optional + node: Option = "node" ], children: [ /// Used for filtering the results. @@ -50,11 +50,11 @@ generate_element!( Result_, "result", MAM, attributes: [ /// The stanza-id under which the archive stored this stanza. - id: String = "id" => required, + id: Required = "id", /// The same queryid as the one requested in the /// [query](struct.Query.html). - queryid: Option = "queryid" => optional, + queryid: Option = "queryid", ], children: [ /// The actual stanza being forwarded. @@ -76,7 +76,7 @@ generate_element!( Fin, "fin", MAM, attributes: [ /// True when the end of a MAM query has been reached. - complete: Complete = "complete" => default + complete: Default = "complete", ], children: [ /// Describes the current page, it should contain at least [first] diff --git a/src/media_element.rs b/src/media_element.rs index 639b71cea3401fcf764ffba7a54e36c760328900..259e9d1226d5a14336f2697c58a4b0113ddfdaa3 100644 --- a/src/media_element.rs +++ b/src/media_element.rs @@ -17,7 +17,7 @@ generate_element!( /// accepted too. /// /// [1]: https://www.iana.org/assignments/media-types/media-types.xhtml - type_: String = "type" => required + type_: Required = "type" ], text: ( /// The actual URI contained. @@ -31,10 +31,10 @@ generate_element!( MediaElement, "media", MEDIA_ELEMENT, attributes: [ /// The recommended display width in pixels. - width: Option = "width" => optional, + width: Option = "width", /// The recommended display height in pixels. - height: Option = "height" => optional + height: Option = "height" ], children: [ /// A list of URIs referencing this media. diff --git a/src/message_correct.rs b/src/message_correct.rs index 05663c8daa34cb40755378242a03e74b1c37d586..b2600e0b9a021f227b0bef80065fb83fa1778a9f 100644 --- a/src/message_correct.rs +++ b/src/message_correct.rs @@ -12,7 +12,7 @@ generate_element!( Replace, "replace", MESSAGE_CORRECT, attributes: [ /// The 'id' attribute of the message getting corrected. - id: String = "id" => required, + id: Required = "id", ] ); diff --git a/src/muc/muc.rs b/src/muc/muc.rs index a4e60a4dd5d0e5c01a76f197fb0e0f6dead86247..898af67896f657699516615e46d3fcaa50e7a8af 100644 --- a/src/muc/muc.rs +++ b/src/muc/muc.rs @@ -14,16 +14,16 @@ generate_element!( History, "history", MUC, attributes: [ /// How many characters of history to send, in XML characters. - maxchars: Option = "maxchars" => optional, + maxchars: Option = "maxchars", /// How many messages to send. - maxstanzas: Option = "maxstanzas" => optional, + maxstanzas: Option = "maxstanzas", /// Only send messages received in these last seconds. - seconds: Option = "seconds" => optional, + seconds: Option = "seconds", /// Only send messages after this date. - since: Option = "since" => optional, + since: Option = "since", ] ); diff --git a/src/muc/user.rs b/src/muc/user.rs index 8232baf0a875d42208003bb624d6ea0106fb040e..73e910ae1bcccb82890fe7d9637756ec6d53486c 100644 --- a/src/muc/user.rs +++ b/src/muc/user.rs @@ -128,7 +128,7 @@ generate_element!( Continue, "continue", MUC_USER, attributes: [ /// The thread to continue in this room. - thread: Option = "thread" => optional, + thread: Option = "thread", ] ); @@ -187,16 +187,16 @@ generate_element!( /// An item representing a user in a room. Item, "item", MUC_USER, attributes: [ /// The affiliation of this user with the room. - affiliation: Affiliation = "affiliation" => required, + affiliation: Required = "affiliation", /// The real JID of this user, if you are allowed to see it. - jid: Option = "jid" => optional, + jid: Option = "jid", /// The current nickname of this user. - nick: Option = "nick" => optional, + nick: Option = "nick", /// The current role of this user. - role: Role = "role" => required + role: Required = "role", ], children: [ /// The actor affected by this item. actor: Option = ("actor", MUC_USER) => Actor, diff --git a/src/pubsub/pubsub.rs b/src/pubsub/pubsub.rs index c7bb6466cd948e83aa21602ef6acf1a9804e0755..5093b3e1512e692bbd02f47f779e311944ebf0e6 100644 --- a/src/pubsub/pubsub.rs +++ b/src/pubsub/pubsub.rs @@ -20,7 +20,7 @@ generate_element!( Affiliations, "affiliations", PUBSUB, attributes: [ /// The optional node name this request pertains to. - node: Option = "node" => optional, + node: Option = "node", ], children: [ /// The actual list of affiliation elements. @@ -56,10 +56,10 @@ generate_element!( Affiliation, "affiliation", PUBSUB, attributes: [ /// The node this affiliation pertains to. - node: NodeName = "node" => required, + node: Required = "node", /// The affiliation you currently have on this node. - affiliation: AffiliationAttribute = "affiliation" => required, + affiliation: Required = "affiliation", ] ); @@ -77,7 +77,7 @@ generate_element!( Create, "create", PUBSUB, attributes: [ /// The node name to create, if `None` the service will generate one. - node: Option = "node" => optional, + node: Option = "node", ] ); @@ -86,10 +86,10 @@ generate_element!( Default, "default", PUBSUB, attributes: [ /// The node targetted by this request, otherwise the entire service. - node: Option = "node" => optional, + node: Option = "node", // TODO: do we really want to support collection nodes? - // type: String = "type" => optional, + // type: Option = "type", ] ); @@ -99,13 +99,13 @@ generate_element!( attributes: [ // TODO: should be an xs:positiveInteger, that is, an unbounded int ≥ 1. /// Maximum number of items returned. - max_items: Option = "max_items" => optional, + max_items: Option = "max_items", /// The node queried by this request. - node: NodeName = "node" => required, + node: Required = "node", /// The subscription identifier related to this request. - subid: Option = "subid" => optional, + subid: Option = "subid", ], children: [ /// The actual list of items returned. @@ -124,13 +124,13 @@ generate_element!( Options, "options", PUBSUB, attributes: [ /// The JID affected by this request. - jid: Jid = "jid" => required, + jid: Required = "jid", /// The node affected by this request. - node: Option = "node" => optional, + node: Option = "node", /// The subscription identifier affected by this request. - subid: Option = "subid" => optional, + subid: Option = "subid", ], children: [ /// The form describing the subscription. @@ -143,7 +143,7 @@ generate_element!( Publish, "publish", PUBSUB, attributes: [ /// The target node for this operation. - node: NodeName = "node" => required, + node: Required = "node", ], children: [ /// The items you want to publish. @@ -172,10 +172,10 @@ generate_element!( Retract, "retract", PUBSUB, attributes: [ /// The node affected by this request. - node: NodeName = "node" => required, + node: Required = "node", /// Whether a retract request should notify subscribers or not. - notify: Notify = "notify" => default, + notify: Default = "notify", ], children: [ /// The items affected by this request. @@ -233,10 +233,10 @@ generate_element!( Subscribe, "subscribe", PUBSUB, attributes: [ /// The JID being subscribed. - jid: Jid = "jid" => required, + jid: Required = "jid", /// The node to subscribe to. - node: Option = "node" => optional, + node: Option = "node", ] ); @@ -245,7 +245,7 @@ generate_element!( Subscriptions, "subscriptions", PUBSUB, attributes: [ /// The node to query. - node: Option = "node" => optional, + node: Option = "node", ], children: [ /// The list of subscription elements returned. @@ -258,16 +258,16 @@ generate_element!( SubscriptionElem, "subscription", PUBSUB, attributes: [ /// The JID affected by this subscription. - jid: Jid = "jid" => required, + jid: Required = "jid", /// The node affected by this subscription. - node: Option = "node" => optional, + node: Option = "node", /// The subscription identifier for this subscription. - subid: Option = "subid" => optional, + subid: Option = "subid", /// The state of the subscription. - subscription: Option = "subscription" => optional, + subscription: Option = "subscription", ], children: [ /// The options related to this subscription. @@ -280,13 +280,13 @@ generate_element!( Unsubscribe, "unsubscribe", PUBSUB, attributes: [ /// The JID affected by this request. - jid: Jid = "jid" => required, + jid: Required = "jid", /// The node affected by this request. - node: Option = "node" => optional, + node: Option = "node", /// The subscription identifier for this subscription. - subid: Option = "subid" => optional, + subid: Option = "subid", ] ); diff --git a/src/receipts.rs b/src/receipts.rs index c97d3e118358630758fa253d5e0153fbea3cf8cc..e60900401ec1510473735441f10d17c24be516d3 100644 --- a/src/receipts.rs +++ b/src/receipts.rs @@ -22,7 +22,7 @@ generate_element!( Received, "received", RECEIPTS, attributes: [ /// The 'id' attribute of the received message. - id: Option = "id" => optional, + id: Option = "id", ] ); diff --git a/src/roster.rs b/src/roster.rs index 29086aec2ae7777b00ffebebcf072a4e2587c458..57d440e97733717d16ff33c86e9c16c8ee938235 100644 --- a/src/roster.rs +++ b/src/roster.rs @@ -50,16 +50,16 @@ generate_element!( Item, "item", ROSTER, attributes: [ /// JID of this contact. - jid: Jid = "jid" => required, + jid: Required = "jid", /// Name of this contact. - name: Option = "name" => optional_empty, + name: OptionEmpty = "name", /// Subscription status of this contact. - subscription: Subscription = "subscription" => default, + subscription: Default = "subscription", /// Indicates “Pending Out” sub-states for this contact. - ask: Ask = "ask" => default, + ask: Default = "ask", ], children: [ @@ -77,7 +77,7 @@ generate_element!( /// This is an opaque string that should only be sent back to the server on /// a new connection, if this client is storing the contact list between /// connections. - ver: Option = "ver" => optional + ver: Option = "ver" ], children: [ /// List of the contacts of the user. diff --git a/src/sasl.rs b/src/sasl.rs index 8f63f092a937ba38e77b2984c04f239a0bd8b745..9d35072e1c25b0bf4709c42e3f9ea4fc53432db1 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -49,7 +49,7 @@ generate_element!( Auth, "auth", SASL, attributes: [ /// The mechanism used. - mechanism: Mechanism = "mechanism" => required + mechanism: Required = "mechanism" ], text: ( /// The content of the handshake. diff --git a/src/sm.rs b/src/sm.rs index 1f48615e30da58c541955deade8c912e86bc04de..661d05b9d0c3f5f73e30a2a47cd8787f7dc84b28 100644 --- a/src/sm.rs +++ b/src/sm.rs @@ -11,7 +11,7 @@ generate_element!( A, "a", SM, attributes: [ /// The last handled stanza. - h: u32 = "h" => required, + h: Required = "h", ] ); @@ -36,10 +36,10 @@ generate_element!( attributes: [ /// The preferred resumption time in seconds by the client. // TODO: should be the infinite integer set ≥ 1. - max: Option = "max" => optional, + max: Option = "max", /// Whether the client wants to be allowed to resume the stream. - resume: ResumeAttr = "resume" => default, + resume: Default = "resume", ] ); @@ -72,18 +72,18 @@ generate_element!( Enabled, "enabled", SM, attributes: [ /// A random identifier used for stream resumption. - id: Option = "id" => optional, + id: Option = "id", /// The preferred IP, domain, IP:port or domain:port location for /// resumption. - location: Option = "location" => optional, + location: Option = "location", /// The preferred resumption time in seconds by the server. // TODO: should be the infinite integer set ≥ 1. - max: Option = "max" => optional, + max: Option = "max", /// Whether stream resumption is allowed. - resume: ResumeAttr = "resume" => default, + resume: Default = "resume", ] ); @@ -92,7 +92,7 @@ generate_element!( Failed, "failed", SM, attributes: [ /// The last handled stanza. - h: Option = "h" => optional, + h: Option = "h", ], children: [ /// The error returned. @@ -113,11 +113,11 @@ generate_element!( Resume, "resume", SM, attributes: [ /// The last handled stanza. - h: u32 = "h" => required, + h: Required = "h", /// The previous id given by the server on /// [enabled](struct.Enabled.html). - previd: StreamId = "previd" => required, + previd: Required = "previd", ] ); @@ -126,11 +126,11 @@ generate_element!( Resumed, "resumed", SM, attributes: [ /// The last handled stanza. - h: u32 = "h" => required, + h: Required = "h", /// The previous id given by the server on /// [enabled](struct.Enabled.html). - previd: StreamId = "previd" => required, + previd: Required = "previd", ] ); diff --git a/src/stanza_id.rs b/src/stanza_id.rs index c9cefad724a1c8583bfdc908a56d777068ab915b..dd8ed9e0a125044eb9587f5364793730f1a12127 100644 --- a/src/stanza_id.rs +++ b/src/stanza_id.rs @@ -13,10 +13,10 @@ generate_element!( StanzaId, "stanza-id", SID, attributes: [ /// The id associated to this stanza by another entity. - id: String = "id" => required, + id: Required = "id", /// The entity who stamped this stanza-id. - by: Jid = "by" => required, + by: Required = "by", ] ); @@ -28,7 +28,7 @@ generate_element!( OriginId, "origin-id", SID, attributes: [ /// The id this client set for this stanza. - id: String = "id" => required, + id: Required = "id", ] ); diff --git a/src/stream.rs b/src/stream.rs index fa416fd80dd7e361169cd909eb175e3a720de6f4..a77a73ea8ca36f59a55df520e085aa29cf9dff85 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -11,20 +11,20 @@ generate_element!( Stream, "stream", STREAM, attributes: [ /// The JID of the entity opening this stream. - from: Option = "from" => optional, + from: Option = "from", /// The JID of the entity receiving this stream opening. - to: Option = "to" => optional, + to: Option = "to", /// The id of the stream, used for authentication challenges. - id: Option = "id" => optional, + id: Option = "id", /// The XMPP version used during this stream. - version: Option = "version" => optional, + version: Option = "version", /// The default human language for all subsequent stanzas, which will /// be transmitted to other entities for better localisation. - xml_lang: Option = "xml:lang" => optional, + xml_lang: Option = "xml:lang", ] ); diff --git a/src/util/macros.rs b/src/util/macros.rs index 0c296abba07e94e05d7fb32db3b7dd749ea5a0a8..74e4009f93471cfdda0112adc51e5a47371bf27e 100644 --- a/src/util/macros.rs +++ b/src/util/macros.rs @@ -8,20 +8,20 @@ macro_rules! get_attr { ($elem:ident, $attr:tt, $type:tt) => { get_attr!($elem, $attr, $type, value, value.parse()?) }; - ($elem:ident, $attr:tt, optional_empty, $value:ident, $func:expr) => { + ($elem:ident, $attr:tt, OptionEmpty, $value:ident, $func:expr) => { match $elem.attr($attr) { Some("") => None, Some($value) => Some($func), None => None, } }; - ($elem:ident, $attr:tt, optional, $value:ident, $func:expr) => { + ($elem:ident, $attr:tt, Option, $value:ident, $func:expr) => { match $elem.attr($attr) { Some($value) => Some($func), None => None, } }; - ($elem:ident, $attr:tt, required, $value:ident, $func:expr) => { + ($elem:ident, $attr:tt, Required, $value:ident, $func:expr) => { match $elem.attr($attr) { Some($value) => $func, None => { @@ -33,12 +33,22 @@ macro_rules! get_attr { } } }; - ($elem:ident, $attr:tt, default, $value:ident, $func:expr) => { + ($elem:ident, $attr:tt, Default, $value:ident, $func:expr) => { match $elem.attr($attr) { Some($value) => $func, None => ::std::default::Default::default(), } }; + // The remaining ones are only for backwards-compatibility. + ($elem:ident, $attr:tt, optional, $value:ident, $func:expr) => { + get_attr!($elem, $attr, Option, $value, $func) + }; + ($elem:ident, $attr:tt, required, $value:ident, $func:expr) => { + get_attr!($elem, $attr, Required, $value, $func) + }; + ($elem:ident, $attr:tt, default, $value:ident, $func:expr) => { + get_attr!($elem, $attr, Default, $value, $func) + }; } macro_rules! generate_attribute { @@ -398,6 +408,21 @@ macro_rules! generate_elem_id { ); } +macro_rules! decl_attr { + (OptionEmpty, $type:ty) => ( + Option<$type> + ); + (Option, $type:ty) => ( + Option<$type> + ); + (Required, $type:ty) => ( + $type + ); + (Default, $type:ty) => ( + $type + ); +} + macro_rules! start_decl { (Vec, $type:ty) => ( Vec<$type> @@ -503,31 +528,31 @@ 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!($(#[$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_action:tt<$attr_type:ty> = $attr_name:tt),+,]) => ( + generate_element!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_action<$attr_type> = $attr_name),*], 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!($(#[$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_action:tt<$attr_type:ty> = $attr_name:tt),+]) => ( + generate_element!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_action<$attr_type> = $attr_name),*], 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!($(#[$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),*]) => ( - 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_action:tt<$attr_type:ty> = $attr_name:tt),*,], children: [$($(#[$child_meta:meta])* $child_ident:ident: $coucou:tt<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),*]) => ( + generate_element!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_action<$attr_type> = $attr_name),*], children: [$($(#[$child_meta])* $child_ident: $coucou<$child_type> = ($child_name, $child_ns) => $child_constructor),*]); ); ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, text: ($(#[$text_meta:meta])* $text_ident:ident: $codec:ident < $text_type:ty >)) => ( generate_element!($(#[$meta])* $elem, $name, $ns, attributes: [], children: [], text: ($(#[$text_meta])* $text_ident: $codec<$text_type>)); ); - ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+], text: ($(#[$text_meta:meta])* $text_ident:ident: $codec:ident < $text_type:ty >)) => ( - generate_element!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: [], text: ($(#[$text_meta])* $text_ident: $codec<$text_type>)); + ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_action:tt<$attr_type:ty> = $attr_name:tt),+], text: ($(#[$text_meta:meta])* $text_ident:ident: $codec:ident < $text_type:ty >)) => ( + generate_element!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_action<$attr_type> = $attr_name),*], children: [], text: ($(#[$text_meta])* $text_ident: $codec<$text_type>)); ); - ($(#[$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),*] $(, text: ($(#[$text_meta:meta])* $text_ident:ident: $codec:ident < $text_type:ty >))*) => ( + ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_action:tt<$attr_type:ty> = $attr_name:tt),*], children: [$($(#[$child_meta:meta])* $child_ident:ident: $coucou:tt<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),*] $(, text: ($(#[$text_meta:meta])* $text_ident:ident: $codec:ident < $text_type:ty >))*) => ( $(#[$meta])* #[derive(Debug, Clone)] pub struct $elem { $( $(#[$attr_meta])* - pub $attr: $attr_type, + pub $attr: decl_attr!($attr_action, $attr_type), )* $( $(#[$child_meta])* diff --git a/src/websocket.rs b/src/websocket.rs index 10693ca7d4bee4f9c6278e65c5a8815791a0123b..03a1d0401b97103d42e81ba45f10f110dae3bea5 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -11,20 +11,20 @@ generate_element!( Open, "open", WEBSOCKET, attributes: [ /// The JID of the entity opening this stream. - from: Option = "from" => optional, + from: Option = "from", /// The JID of the entity receiving this stream opening. - to: Option = "to" => optional, + to: Option = "to", /// The id of the stream, used for authentication challenges. - id: Option = "id" => optional, + id: Option = "id", /// The XMPP version used during this stream. - version: Option = "version" => optional, + version: Option = "version", /// The default human language for all subsequent stanzas, which will /// be transmitted to other entities for better localisation. - xml_lang: Option = "xml:lang" => optional, + xml_lang: Option = "xml:lang", ] );