From 69f480e7099c91a3894e804141115dc22483289a Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 3 Jul 2024 11:06:33 +0200 Subject: [PATCH] xmpp-parsers: Fix most of the clippy warnings Only the non-looping loop is kept for now, until we find a better solution. --- 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(-) diff --git a/parsers/src/data_forms.rs b/parsers/src/data_forms.rs index 37ad5619..b7a839af 100644 --- a/parsers/src/data_forms.rs +++ b/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: diff --git a/parsers/src/data_forms_validate.rs b/parsers/src/data_forms_validate.rs index 757aeb32..d2fa42f5 100644 --- a/parsers/src/data_forms_validate.rs +++ b/parsers/src/data_forms_validate.rs @@ -295,7 +295,7 @@ impl TryFrom 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) } diff --git a/parsers/src/ecaps2.rs b/parsers/src/ecaps2.rs index 3e6b1960..49c29128 100644 --- a/parsers/src/ecaps2.rs +++ b/parsers/src/ecaps2.rs @@ -163,8 +163,8 @@ pub fn hash_ecaps2(data: &[u8], algo: Algo) -> Result { 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, }) diff --git a/parsers/src/presence.rs b/parsers/src/presence.rs index 33ae2284..35d0a564 100644 --- a/parsers/src/presence.rs +++ b/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.", + )); } }) } diff --git a/parsers/src/pubsub/event.rs b/parsers/src/pubsub/event.rs index a2b0c8fc..d1541501 100644 --- a/parsers/src/pubsub/event.rs +++ b/parsers/src/pubsub/event.rs @@ -97,7 +97,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result { 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 { 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 { 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 { 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, } } } diff --git a/parsers/src/rtt.rs b/parsers/src/rtt.rs index 9def1aa0..91b5f08a 100644 --- a/parsers/src/rtt.rs +++ b/parsers/src/rtt.rs @@ -225,7 +225,7 @@ impl TryFrom for Rtt { seq, event, id, - actions: actions, + actions, }) } } diff --git a/parsers/src/stanza_error.rs b/parsers/src/stanza_error.rs index f274931e..ab3b1c02 100644 --- a/parsers/src/stanza_error.rs +++ b/parsers/src/stanza_error.rs @@ -291,7 +291,7 @@ impl TryFrom 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()) }); } diff --git a/parsers/src/vcard.rs b/parsers/src/vcard.rs index a11d5d2c..867f1a28 100644 --- a/parsers/src/vcard.rs +++ b/parsers/src/vcard.rs @@ -62,7 +62,9 @@ impl TryFrom for VCard { fn try_from(value: Element) -> Result { // Check that the root element is if !value.is("vCard", ns::VCARD) { - return Err(Error::Other("Root element is not ").into()); + return Err(Error::Other( + "Root element is not ", + )); } // Parse the element, if any. @@ -76,15 +78,11 @@ impl TryFrom for VCard { } } -impl Into 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 for Element { + fn from(vcard: VCard) -> Element { + Element::builder("vCard", ns::VCARD) + .append_all(vcard.photo) + .build() } }