xmpp-parsers: Fix most of the clippy warnings

Emmanuel Gil Peyrot created

Only the non-looping loop is kept for now, until we find a better
solution.

Change summary

parsers/src/data_forms.rs          |  6 +-----
parsers/src/data_forms_validate.rs |  2 +-
parsers/src/ecaps2.rs              |  4 ++--
parsers/src/presence.rs            |  8 +++++---
parsers/src/pubsub/event.rs        | 20 ++++++++++----------
parsers/src/rtt.rs                 |  2 +-
parsers/src/stanza_error.rs        |  2 +-
parsers/src/vcard.rs               | 18 ++++++++----------
8 files changed, 29 insertions(+), 33 deletions(-)

Detailed changes

parsers/src/data_forms.rs 🔗

@@ -156,11 +156,7 @@ impl Field {
             // > treat a FORM_TYPE field without an explicit type attribute,
             // > in data forms of type "submit", as the FORM_TYPE field with
             // > the special meaning defined herein.
-            DataFormType::Submit => match self.type_ {
-                FieldType::Hidden => true,
-                FieldType::TextSingle => true,
-                _ => false,
-            },
+            DataFormType::Submit => matches!(self.type_, FieldType::Hidden | FieldType::TextSingle),
 
             // XEP-0068 does not explicitly mention cancel type forms.
             // However, XEP-0004 states:

parsers/src/data_forms_validate.rs 🔗

@@ -295,7 +295,7 @@ impl TryFrom<Element> for Method {
                 check_no_children!(elem, "regex");
                 Method::Regex(elem.text())
             }
-            _ => return Err(Error::Other("Encountered invalid validation method.").into()),
+            _ => return Err(Error::Other("Encountered invalid validation method.")),
         };
         Ok(method)
     }

parsers/src/ecaps2.rs 🔗

@@ -163,8 +163,8 @@ pub fn hash_ecaps2(data: &[u8], algo: Algo) -> Result<Hash, Error> {
                 hasher.finalize_variable(&mut vec).unwrap();
                 vec
             }
-            Algo::Sha_1 => return Err(Error::Other("Disabled algorithm sha-1: unsafe.").into()),
-            Algo::Unknown(_algo) => return Err(Error::Other("Unknown algorithm in ecaps2.").into()),
+            Algo::Sha_1 => return Err(Error::Other("Disabled algorithm sha-1: unsafe.")),
+            Algo::Unknown(_algo) => return Err(Error::Other("Unknown algorithm in ecaps2.")),
         },
         algo,
     })

parsers/src/presence.rs 🔗

@@ -42,7 +42,7 @@ impl FromStr for Show {
             "dnd" => Show::Dnd,
             "xa" => Show::Xa,
 
-            _ => return Err(Error::Other("Invalid value for show.").into()),
+            _ => return Err(Error::Other("Invalid value for show.")),
         })
     }
 }
@@ -65,7 +65,7 @@ type Status = String;
 
 type Priority = i8;
 
-///
+/// Accepted values for the 'type' attribute of a presence.
 #[derive(Debug, Default, Clone, PartialEq)]
 pub enum Type {
     /// This value is not an acceptable 'type' attribute, it is only used
@@ -114,7 +114,9 @@ impl FromStr for Type {
             "unsubscribed" => Type::Unsubscribed,
 
             _ => {
-                return Err(Error::Other("Invalid 'type' attribute on presence element.").into());
+                return Err(Error::Other(
+                    "Invalid 'type' attribute on presence element.",
+                ));
             }
         })
     }

parsers/src/pubsub/event.rs 🔗

@@ -97,7 +97,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
                 None => is_retract = Some(false),
                 Some(false) => (),
                 Some(true) => {
-                    return Err(Error::Other("Mix of item and retract in items element.").into());
+                    return Err(Error::Other("Mix of item and retract in items element."));
                 }
             }
             items.push(Item::try_from(child.clone())?);
@@ -106,7 +106,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
                 None => is_retract = Some(true),
                 Some(true) => (),
                 Some(false) => {
-                    return Err(Error::Other("Mix of item and retract in items element.").into());
+                    return Err(Error::Other("Mix of item and retract in items element."));
                 }
             }
             check_no_children!(child, "retract");
@@ -114,7 +114,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
             let id = get_attr!(child, "id", Required);
             retracts.push(id);
         } else {
-            return Err(Error::Other("Invalid child in items element.").into());
+            return Err(Error::Other("Invalid child in items element."));
         }
     }
     Ok(match is_retract {
@@ -123,7 +123,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
             node,
             items: retracts,
         },
-        None => return Err(Error::Other("Missing children in items element.").into()),
+        None => return Err(Error::Other("Missing children in items element.")),
     })
 }
 
@@ -242,12 +242,12 @@ impl PubSubEvent {
     /// Return the name of the node to which this event is related.
     pub fn node_name(&self) -> &NodeName {
         match self {
-            Self::Purge { node, .. } => &node,
-            Self::PublishedItems { node, .. } => &node,
-            Self::RetractedItems { node, .. } => &node,
-            Self::Subscription { node, .. } => &node,
-            Self::Delete { node, .. } => &node,
-            Self::Configuration { node, .. } => &node,
+            Self::Purge { node, .. } => node,
+            Self::PublishedItems { node, .. } => node,
+            Self::RetractedItems { node, .. } => node,
+            Self::Subscription { node, .. } => node,
+            Self::Delete { node, .. } => node,
+            Self::Configuration { node, .. } => node,
         }
     }
 }

parsers/src/rtt.rs 🔗

@@ -225,7 +225,7 @@ impl TryFrom<Element> for Rtt {
             seq,
             event,
             id,
-            actions: actions,
+            actions,
         })
     }
 }

parsers/src/stanza_error.rs 🔗

@@ -291,7 +291,7 @@ impl TryFrom<Element> for StanzaError {
                 if condition == DefinedCondition::Gone || condition == DefinedCondition::Redirect {
                     stanza_error.alternate_address = child.nodes().find_map(|node| {
                         let Node::Text(text) = node else { return None };
-                        return Some(text.to_string());
+                        Some(text.to_string())
                     });
                 }
 

parsers/src/vcard.rs 🔗

@@ -62,7 +62,9 @@ impl TryFrom<Element> for VCard {
     fn try_from(value: Element) -> Result<Self, Self::Error> {
         // Check that the root element is <vCard>
         if !value.is("vCard", ns::VCARD) {
-            return Err(Error::Other("Root element is not <vCard xmlns='vcard-temp'>").into());
+            return Err(Error::Other(
+                "Root element is not <vCard xmlns='vcard-temp'>",
+            ));
         }
 
         // Parse the <PHOTO> element, if any.
@@ -76,15 +78,11 @@ impl TryFrom<Element> for VCard {
     }
 }
 
-impl Into<Element> for VCard {
-    fn into(self) -> Element {
-        let mut builder = Element::builder("vCard", ns::VCARD);
-
-        if let Some(photo) = self.photo {
-            builder = builder.append(photo);
-        }
-
-        builder.build()
+impl From<VCard> for Element {
+    fn from(vcard: VCard) -> Element {
+        Element::builder("vCard", ns::VCARD)
+            .append_all(vcard.photo)
+            .build()
     }
 }