xmpp-parsers: Use the new lang meta everywhere

Link Mauve created

Stop parsing xml:lang manually, instead use the #[xml(lang)] meta which
tracks it using the XML semantics, inheriting it from the most recent
ancestor.

skip-changelog: This isn’t a user-facing change.

Change summary

parsers/src/jingle.rs         | 2 +-
parsers/src/jingle_ft.rs      | 2 +-
parsers/src/message.rs        | 4 ++--
parsers/src/presence.rs       | 2 +-
parsers/src/sasl.rs           | 2 +-
parsers/src/spam_reporting.rs | 2 +-
parsers/src/stanza_error.rs   | 2 +-
parsers/src/stream_error.rs   | 5 ++++-
8 files changed, 12 insertions(+), 9 deletions(-)

Detailed changes

parsers/src/jingle.rs πŸ”—

@@ -473,7 +473,7 @@ pub struct ReasonElement {
 
     /// A human-readable description of this reason.
     #[xml(extract(n = .., namespace = ns::JINGLE, name = "text", fields(
-        attribute(type_ = String, name = "xml:lang", default),
+        lang(type_ = Lang, default),
         text(type_ = String),
     )))]
     pub texts: BTreeMap<Lang, String>,

parsers/src/jingle_ft.rs πŸ”—

@@ -58,7 +58,7 @@ pub struct File {
 
     /// The description of this file, possibly localised.
     #[xml(extract(n = .., name = "desc", fields(
-        attribute(name = "xml:lang", type_ = String),
+        lang(type_ = Lang, default),
         text(type_ = String)
     )))]
     pub descs: BTreeMap<Lang, String>,

parsers/src/message.rs πŸ”—

@@ -167,7 +167,7 @@ pub struct Message {
     /// A list of bodies, sorted per language.  Use
     /// [get_best_body()](#method.get_best_body) to access them on reception.
     #[xml(extract(n = .., name = "body", fields(
-        attribute(name = "xml:lang", type_ = Lang, default),
+        lang(type_ = Lang, default),
         text(type_ = String),
     )))]
     pub bodies: BTreeMap<Lang, String>,
@@ -176,7 +176,7 @@ pub struct Message {
     /// [get_best_subject()](#method.get_best_subject) to access them on
     /// reception.
     #[xml(extract(n = .., name = "subject", fields(
-        attribute(name = "xml:lang", type_ = Lang, default),
+        lang(type_ = Lang, default),
         text(type_ = String),
     )))]
     pub subjects: BTreeMap<Lang, String>,

parsers/src/presence.rs πŸ”—

@@ -163,7 +163,7 @@ pub struct Presence {
 
     /// A localised list of statuses defined in this presence.
     #[xml(extract(n = .., name = "status", fields(
-        attribute(type_ = Lang, name = "xml:lang", default),
+        lang(type_ = Lang, default),
         text(type_ = String),
     )))]
     pub statuses: BTreeMap<Lang, Status>,

parsers/src/sasl.rs πŸ”—

@@ -157,7 +157,7 @@ pub struct Failure {
 
     /// A human-readable explanation for the failure.
     #[xml(extract(n = .., name = "text", fields(
-        attribute(type_ = String, name = "xml:lang", default),
+        lang(type_ = Lang, default),
         text(type_ = String),
     )))]
     pub texts: BTreeMap<Lang, String>,

parsers/src/spam_reporting.rs πŸ”—

@@ -37,7 +37,7 @@ pub struct Report {
 
     /// Some text explaining the reason for this report.
     #[xml(extract(n = .., name = "text", fields(
-        attribute(name = "xml:lang", type_ = Lang),
+        lang(type_ = Lang, default),
         text(type_ = String)
     )))]
     texts: BTreeMap<Lang, String>,

parsers/src/stanza_error.rs πŸ”—

@@ -245,7 +245,7 @@ pub struct StanzaError {
 
     /// Human-readable description of this error.
     #[xml(extract(n = .., namespace = ns::XMPP_STANZAS, name = "text", fields(
-        attribute(name = "xml:lang", type_ = Lang, default),
+        lang(type_ = Lang, default),
         text(type_ = String),
     )))]
     pub texts: BTreeMap<Lang, String>,

parsers/src/stream_error.rs πŸ”—

@@ -307,7 +307,10 @@ pub struct StreamError {
 
     /// Optional error text. The first part is the optional `xml:lang`
     /// language tag, the second part is the actual text content.
-    #[xml(extract(default, fields(attribute(name = "xml:lang", default, type_ = Option<String>), text(type_ = String))))]
+    #[xml(extract(default, fields(
+        lang(type_ = Option<String>, default),
+        text(type_ = String),
+    )))]
     pub text: Option<(Option<String>, String)>,
 
     /// Optional application-defined element which refines the specified