diff --git a/src/blocking.rs b/src/blocking.rs index 2b021185..74e84bc6 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -41,7 +41,7 @@ macro_rules! generate_blocking_element { check_self!(child, "item", BLOCKING); check_no_unknown_attributes!(child, "item", ["jid"]); check_no_children!(child, "item"); - items.push(get_attr!(child, "jid", required)); + items.push(get_attr!(child, "jid", Required)); } Ok($elem { items }) } diff --git a/src/caps.rs b/src/caps.rs index 1a0d5769..452fa6d5 100644 --- a/src/caps.rs +++ b/src/caps.rs @@ -46,14 +46,14 @@ impl TryFrom for Caps { check_self!(elem, "c", CAPS, "caps"); check_no_children!(elem, "caps"); check_no_unknown_attributes!(elem, "caps", ["hash", "ver", "ext", "node"]); - let ver: String = get_attr!(elem, "ver", required); + let ver: String = get_attr!(elem, "ver", Required); let hash = Hash { - algo: get_attr!(elem, "hash", required), + algo: get_attr!(elem, "hash", Required), hash: base64::decode(&ver)?, }; Ok(Caps { - ext: get_attr!(elem, "ext", optional), - node: get_attr!(elem, "node", required), + ext: get_attr!(elem, "ext", Option), + node: get_attr!(elem, "node", Required), hash, }) } diff --git a/src/data_forms.rs b/src/data_forms.rs index 9a1ed3e3..296614e9 100644 --- a/src/data_forms.rs +++ b/src/data_forms.rs @@ -106,9 +106,9 @@ impl TryFrom for Field { check_self!(elem, "field", DATA_FORMS); check_no_unknown_attributes!(elem, "field", ["label", "type", "var"]); let mut field = Field { - var: get_attr!(elem, "var", required), - type_: get_attr!(elem, "type", default), - label: get_attr!(elem, "label", optional), + var: get_attr!(elem, "var", Required), + type_: get_attr!(elem, "type", Default), + label: get_attr!(elem, "label", Option), required: false, options: vec![], values: vec![], @@ -220,7 +220,7 @@ impl TryFrom for DataForm { fn try_from(elem: Element) -> Result { check_self!(elem, "x", DATA_FORMS); check_no_unknown_attributes!(elem, "x", ["type"]); - let type_ = get_attr!(elem, "type", required); + let type_ = get_attr!(elem, "type", Required); let mut form = DataForm { type_, form_type: None, diff --git a/src/disco.rs b/src/disco.rs index 43c15903..0acdcb86 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -71,14 +71,14 @@ impl TryFrom for Identity { ["category", "type", "xml:lang", "name"] ); - let category = get_attr!(elem, "category", required); + let category = get_attr!(elem, "category", Required); if category == "" { return Err(Error::ParseError( "Identity must have a non-empty 'category' attribute.", )); } - let type_ = get_attr!(elem, "type", required); + let type_ = get_attr!(elem, "type", Required); if type_ == "" { return Err(Error::ParseError( "Identity must have a non-empty 'type' attribute.", @@ -88,8 +88,8 @@ impl TryFrom for Identity { Ok(Identity { category, type_, - lang: get_attr!(elem, "xml:lang", optional), - name: get_attr!(elem, "name", optional), + lang: get_attr!(elem, "xml:lang", Option), + name: get_attr!(elem, "name", Option), }) } } @@ -135,7 +135,7 @@ impl TryFrom for DiscoInfoResult { check_no_unknown_attributes!(elem, "disco#info result", ["node"]); let mut result = DiscoInfoResult { - node: get_attr!(elem, "node", optional), + node: get_attr!(elem, "node", Option), identities: vec![], features: vec![], extensions: vec![], diff --git a/src/iq.rs b/src/iq.rs index dd04e6b8..e62a4cd8 100644 --- a/src/iq.rs +++ b/src/iq.rs @@ -134,10 +134,10 @@ impl TryFrom for Iq { fn try_from(root: Element) -> Result { check_self!(root, "iq", DEFAULT_NS); - let from = get_attr!(root, "from", optional); - let to = get_attr!(root, "to", optional); - let id = get_attr!(root, "id", required); - let type_: String = get_attr!(root, "type", required); + let from = get_attr!(root, "from", Option); + let to = get_attr!(root, "to", Option); + let id = get_attr!(root, "id", Required); + let type_: String = get_attr!(root, "type", Required); let mut payload = None; let mut error_payload = None; diff --git a/src/jingle.rs b/src/jingle.rs index b891ab7c..2c6c3fb8 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -492,10 +492,10 @@ impl TryFrom for Jingle { check_no_unknown_attributes!(root, "Jingle", ["action", "initiator", "responder", "sid"]); let mut jingle = Jingle { - action: get_attr!(root, "action", required), - initiator: get_attr!(root, "initiator", optional), - responder: get_attr!(root, "responder", optional), - sid: get_attr!(root, "sid", required), + action: get_attr!(root, "action", Required), + initiator: get_attr!(root, "initiator", Option), + responder: get_attr!(root, "responder", Option), + sid: get_attr!(root, "sid", Required), contents: vec![], reason: None, other: vec![], diff --git a/src/jingle_ft.rs b/src/jingle_ft.rs index 67c055e2..3cd9e00a 100644 --- a/src/jingle_ft.rs +++ b/src/jingle_ft.rs @@ -163,7 +163,7 @@ impl TryFrom for File { } file.name = Some(child.text()); } else if child.is("desc", ns::JINGLE_FT) { - let lang = get_attr!(child, "xml:lang", default); + let lang = get_attr!(child, "xml:lang", Default); let desc = Desc(child.text()); if file.descs.insert(lang, desc).is_some() { return Err(Error::ParseError( @@ -321,8 +321,8 @@ impl TryFrom for Checksum { )); } Ok(Checksum { - name: get_attr!(elem, "name", required), - creator: get_attr!(elem, "creator", required), + name: get_attr!(elem, "name", Required), + creator: get_attr!(elem, "creator", Required), file: file.unwrap(), }) } diff --git a/src/jingle_message.rs b/src/jingle_message.rs index 1a520223..8561a649 100644 --- a/src/jingle_message.rs +++ b/src/jingle_message.rs @@ -39,7 +39,7 @@ pub enum JingleMI { fn get_sid(elem: Element) -> Result { check_no_unknown_attributes!(elem, "Jingle message", ["id"]); - Ok(SessionId(get_attr!(elem, "id", required))) + Ok(SessionId(get_attr!(elem, "id", Required))) } fn check_empty_and_get_sid(elem: Element) -> Result { diff --git a/src/jingle_s5b.rs b/src/jingle_s5b.rs index 1f3a3ee6..02b97361 100644 --- a/src/jingle_s5b.rs +++ b/src/jingle_s5b.rs @@ -177,9 +177,9 @@ impl TryFrom for Transport { fn try_from(elem: Element) -> Result { check_self!(elem, "transport", JINGLE_S5B); check_no_unknown_attributes!(elem, "transport", ["sid", "dstaddr", "mode"]); - let sid = get_attr!(elem, "sid", required); - let dstaddr = get_attr!(elem, "dstaddr", optional); - let mode = get_attr!(elem, "mode", default); + let sid = get_attr!(elem, "sid", Required); + let dstaddr = get_attr!(elem, "dstaddr", Option); + let mode = get_attr!(elem, "mode", Default); let mut payload = None; for child in elem.children() { @@ -200,7 +200,7 @@ impl TryFrom for Transport { "Non-activated child already present in JingleS5B transport element.", )); } - let cid = get_attr!(child, "cid", required); + let cid = get_attr!(child, "cid", Required); TransportPayload::Activated(cid) } else if child.is("candidate-error", ns::JINGLE_S5B) { if payload.is_some() { @@ -215,7 +215,7 @@ impl TryFrom for Transport { "Non-candidate-used child already present in JingleS5B transport element.", )); } - let cid = get_attr!(child, "cid", required); + let cid = get_attr!(child, "cid", Required); TransportPayload::CandidateUsed(cid) } else if child.is("proxy-error", ns::JINGLE_S5B) { if payload.is_some() { diff --git a/src/mam.rs b/src/mam.rs index b68dabb2..cc606923 100644 --- a/src/mam.rs +++ b/src/mam.rs @@ -152,7 +152,7 @@ impl TryFrom for Prefs { return Err(Error::ParseError("Unknown child in prefs element.")); } } - let default_ = get_attr!(elem, "default", required); + let default_ = get_attr!(elem, "default", Required); Ok(Prefs { default_, always, diff --git a/src/message.rs b/src/message.rs index f2611acc..29708c32 100644 --- a/src/message.rs +++ b/src/message.rs @@ -154,10 +154,10 @@ impl TryFrom for Message { fn try_from(root: Element) -> Result { check_self!(root, "message", DEFAULT_NS); - let from = get_attr!(root, "from", optional); - let to = get_attr!(root, "to", optional); - let id = get_attr!(root, "id", optional); - let type_ = get_attr!(root, "type", default); + let from = get_attr!(root, "from", Option); + let to = get_attr!(root, "to", Option); + let id = get_attr!(root, "id", Option); + let type_ = get_attr!(root, "type", Default); let mut bodies = BTreeMap::new(); let mut subjects = BTreeMap::new(); let mut thread = None; @@ -165,7 +165,7 @@ impl TryFrom for Message { for elem in root.children() { if elem.is("body", ns::DEFAULT_NS) { check_no_children!(elem, "body"); - let lang = get_attr!(elem, "xml:lang", default); + let lang = get_attr!(elem, "xml:lang", Default); let body = Body(elem.text()); if bodies.insert(lang, body).is_some() { return Err(Error::ParseError( @@ -174,7 +174,7 @@ impl TryFrom for Message { } } else if elem.is("subject", ns::DEFAULT_NS) { check_no_children!(elem, "subject"); - let lang = get_attr!(elem, "xml:lang", default); + let lang = get_attr!(elem, "xml:lang", Default); let subject = Subject(elem.text()); if subjects.insert(lang, subject).is_some() { return Err(Error::ParseError( diff --git a/src/muc/user.rs b/src/muc/user.rs index 73e910ae..8965529f 100644 --- a/src/muc/user.rs +++ b/src/muc/user.rs @@ -95,8 +95,8 @@ impl TryFrom for Actor { check_self!(elem, "actor", MUC_USER); check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]); check_no_children!(elem, "actor"); - let jid: Option = get_attr!(elem, "jid", optional); - let nick = get_attr!(elem, "nick", optional); + let jid: Option = get_attr!(elem, "jid", Option); + let nick = get_attr!(elem, "nick", Option); match (jid, nick) { (Some(_), Some(_)) | (None, None) => { diff --git a/src/presence.rs b/src/presence.rs index e7d2a55d..2bf09d04 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -263,10 +263,10 @@ impl TryFrom for Presence { let mut show = None; let mut priority = None; let mut presence = Presence { - from: get_attr!(root, "from", optional), - to: get_attr!(root, "to", optional), - id: get_attr!(root, "id", optional), - type_: get_attr!(root, "type", default), + from: get_attr!(root, "from", Option), + to: get_attr!(root, "to", Option), + id: get_attr!(root, "id", Option), + type_: get_attr!(root, "type", Default), show: Show::None, statuses: BTreeMap::new(), priority: 0i8, @@ -285,7 +285,7 @@ impl TryFrom for Presence { } else if elem.is("status", ns::DEFAULT_NS) { check_no_unknown_attributes!(elem, "status", ["xml:lang"]); check_no_children!(elem, "status"); - let lang = get_attr!(elem, "xml:lang", default); + let lang = get_attr!(elem, "xml:lang", Default); if presence.statuses.insert(lang, elem.text()).is_some() { return Err(Error::ParseError( "Status element present twice for the same xml:lang.", diff --git a/src/pubsub/event.rs b/src/pubsub/event.rs index 0c616ab6..8f6951d9 100644 --- a/src/pubsub/event.rs +++ b/src/pubsub/event.rs @@ -115,7 +115,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result { } check_no_children!(child, "retract"); check_no_unknown_attributes!(child, "retract", ["id"]); - let id = get_attr!(child, "id", required); + let id = get_attr!(child, "id", Required); retracts.push(id); } else { return Err(Error::ParseError("Invalid child in items element.")); @@ -140,7 +140,7 @@ impl TryFrom for PubSubEvent { let mut payload = None; for child in elem.children() { - let node = get_attr!(child, "node", required); + let node = get_attr!(child, "node", Required); if child.is("configuration", ns::PUBSUB_EVENT) { let mut payloads = child.children().cloned().collect::>(); let item = payloads.pop(); @@ -163,7 +163,7 @@ impl TryFrom for PubSubEvent { "More than one redirect in delete element.", )); } - let uri = get_attr!(item, "uri", required); + let uri = get_attr!(item, "uri", Required); redirect = Some(uri); } else { return Err(Error::ParseError("Unknown child in delete element.")); @@ -179,10 +179,10 @@ impl TryFrom for PubSubEvent { check_no_children!(child, "subscription"); payload = Some(PubSubEvent::Subscription { node, - expiry: get_attr!(child, "expiry", optional), - jid: get_attr!(child, "jid", optional), - subid: get_attr!(child, "subid", optional), - subscription: get_attr!(child, "subscription", optional), + expiry: get_attr!(child, "expiry", Option), + jid: get_attr!(child, "jid", Option), + subid: get_attr!(child, "subid", Option), + subscription: get_attr!(child, "subscription", Option), }); } else { return Err(Error::ParseError("Unknown child in event element.")); diff --git a/src/rsm.rs b/src/rsm.rs index 1dd5f47f..6b65e3b4 100644 --- a/src/rsm.rs +++ b/src/rsm.rs @@ -131,7 +131,7 @@ impl TryFrom for SetResult { if set.first.is_some() { return Err(Error::ParseError("Set can’t have more than one first.")); } - set.first_index = get_attr!(child, "index", optional); + set.first_index = get_attr!(child, "index", Option); set.first = Some(child.text()); } else if child.is("last", ns::RSM) { if set.last.is_some() { diff --git a/src/sasl.rs b/src/sasl.rs index 9d35072e..ec84fe6c 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -164,7 +164,7 @@ impl TryFrom for Failure { if child.is("text", ns::SASL) { check_no_unknown_attributes!(child, "text", ["xml:lang"]); check_no_children!(child, "text"); - let lang = get_attr!(child, "xml:lang", default); + let lang = get_attr!(child, "xml:lang", Default); if texts.insert(lang, child.text()).is_some() { return Err(Error::ParseError( "Text element present twice for the same xml:lang in failure element.", diff --git a/src/stanza_error.rs b/src/stanza_error.rs index d254f6b4..3488b9c1 100644 --- a/src/stanza_error.rs +++ b/src/stanza_error.rs @@ -221,8 +221,8 @@ impl TryFrom for StanzaError { fn try_from(elem: Element) -> Result { check_self!(elem, "error", DEFAULT_NS); - let type_ = get_attr!(elem, "type", required); - let by = get_attr!(elem, "by", optional); + let type_ = get_attr!(elem, "type", Required); + let by = get_attr!(elem, "by", Option); let mut defined_condition = None; let mut texts = BTreeMap::new(); let mut other = None; @@ -230,7 +230,7 @@ impl TryFrom for StanzaError { for child in elem.children() { if child.is("text", ns::XMPP_STANZAS) { check_no_children!(child, "text"); - let lang = get_attr!(elem, "xml:lang", default); + let lang = get_attr!(elem, "xml:lang", Default); if texts.insert(lang, child.text()).is_some() { return Err(Error::ParseError( "Text element present twice for the same xml:lang.", diff --git a/src/util/macros.rs b/src/util/macros.rs index 74e4009f..a67afe1f 100644 --- a/src/util/macros.rs +++ b/src/util/macros.rs @@ -39,16 +39,6 @@ macro_rules! get_attr { 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 { @@ -242,7 +232,7 @@ macro_rules! generate_attribute_enum { check_ns_only!(elem, $name, $ns); check_no_children!(elem, $name); check_no_unknown_attributes!(elem, $name, [$attr]); - Ok(match get_attr!(elem, $attr, required) { + Ok(match get_attr!(elem, $attr, Required) { $($enum_name => $elem::$enum,)+ _ => return Err(crate::util::error::Error::ParseError(concat!("Invalid ", $name, " ", $attr, " value."))), }) @@ -639,8 +629,8 @@ macro_rules! impl_pubsub_item { )); } Ok($item(crate::pubsub::Item { - id: get_attr!(elem, "id", optional), - publisher: get_attr!(elem, "publisher", optional), + id: get_attr!(elem, "id", Option), + publisher: get_attr!(elem, "publisher", Option), payload, })) }