From b522eaf7f385d17dd4073a583cca96e0590175e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 15 Dec 2023 20:15:35 +0100 Subject: [PATCH] parsers: clippy pass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- parsers/src/bookmarks2.rs | 2 +- parsers/src/caps.rs | 2 +- parsers/src/disco.rs | 4 ++-- parsers/src/http_upload.rs | 2 +- parsers/src/message.rs | 2 +- parsers/src/muc/mod.rs | 1 + parsers/src/muc/user.rs | 6 ++++++ parsers/src/presence.rs | 13 ++++--------- parsers/src/pubsub/event.rs | 2 +- parsers/src/pubsub/mod.rs | 1 + parsers/src/rtt.rs | 6 +++--- parsers/src/util/helpers.rs | 2 +- parsers/src/xhtml.rs | 21 ++++++++++----------- 13 files changed, 33 insertions(+), 31 deletions(-) diff --git a/parsers/src/bookmarks2.rs b/parsers/src/bookmarks2.rs index 81dfab8..1a6d079 100644 --- a/parsers/src/bookmarks2.rs +++ b/parsers/src/bookmarks2.rs @@ -56,7 +56,7 @@ impl TryFrom for Conference { extensions: Vec::new(), }; - for child in root.children().cloned() { + for child in root.children() { if child.is("nick", ns::BOOKMARKS2) { if conference.nick.is_some() { return Err(Error::ParseError( diff --git a/parsers/src/caps.rs b/parsers/src/caps.rs index 9a96f21..673d00a 100644 --- a/parsers/src/caps.rs +++ b/parsers/src/caps.rs @@ -49,7 +49,7 @@ impl TryFrom for Caps { let ver: String = get_attr!(elem, "ver", Required); let hash = Hash { algo: get_attr!(elem, "hash", Required), - hash: Base64.decode(&ver)?, + hash: Base64.decode(ver)?, }; Ok(Caps { ext: get_attr!(elem, "ext", Option), diff --git a/parsers/src/disco.rs b/parsers/src/disco.rs index db162cf..8eff50b 100644 --- a/parsers/src/disco.rs +++ b/parsers/src/disco.rs @@ -177,8 +177,8 @@ impl From for Element { fn from(disco: DiscoInfoResult) -> Element { Element::builder("query", ns::DISCO_INFO) .attr("node", disco.node) - .append_all(disco.identities.into_iter()) - .append_all(disco.features.into_iter()) + .append_all(disco.identities) + .append_all(disco.features) .append_all(disco.extensions.iter().cloned().map(Element::from)) .build() } diff --git a/parsers/src/http_upload.rs b/parsers/src/http_upload.rs index 228f85a..39815ab 100644 --- a/parsers/src/http_upload.rs +++ b/parsers/src/http_upload.rs @@ -48,7 +48,7 @@ impl TryFrom for Header { check_no_children!(elem, "header"); check_no_unknown_attributes!(elem, "header", ["name"]); let name: String = get_attr!(elem, "name", Required); - let text = String::from(elem.text()); + let text = elem.text(); Ok(match name.to_lowercase().as_str() { "authorization" => Header::Authorization(text), diff --git a/parsers/src/message.rs b/parsers/src/message.rs index 45b58f9..4a34c06 100644 --- a/parsers/src/message.rs +++ b/parsers/src/message.rs @@ -291,7 +291,7 @@ impl From for Element { ); body })) - .append_all(message.payloads.into_iter()) + .append_all(message.payloads) .build() } } diff --git a/parsers/src/muc/mod.rs b/parsers/src/muc/mod.rs index 4d4ce41..faabf38 100644 --- a/parsers/src/muc/mod.rs +++ b/parsers/src/muc/mod.rs @@ -5,6 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. /// The `http://jabber.org/protocol/muc` protocol. +#[allow(clippy::module_inception)] pub mod muc; /// The `http://jabber.org/protocol/muc#user` protocol. diff --git a/parsers/src/muc/user.rs b/parsers/src/muc/user.rs index a60cc36..c4947d7 100644 --- a/parsers/src/muc/user.rs +++ b/parsers/src/muc/user.rs @@ -271,6 +271,12 @@ generate_element!( ] ); +impl Default for MucUser { + fn default() -> Self { + Self::new() + } +} + impl MucUser { /// Creates an empty MucUser pub fn new() -> MucUser { diff --git a/parsers/src/presence.rs b/parsers/src/presence.rs index dc7aa33..efe799e 100644 --- a/parsers/src/presence.rs +++ b/parsers/src/presence.rs @@ -67,10 +67,11 @@ type Status = String; type Priority = i8; /// -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Default, Clone, PartialEq)] pub enum Type { /// This value is not an acceptable 'type' attribute, it is only used /// internally to signal the absence of 'type'. + #[default] None, /// An error has occurred regarding processing of a previously sent @@ -100,12 +101,6 @@ pub enum Type { Unsubscribed, } -impl Default for Type { - fn default() -> Type { - Type::None - } -} - impl FromStr for Type { type Err = Error; @@ -350,7 +345,7 @@ impl From for Element { .attr("to", presence.to) .attr("id", presence.id) .attr("type", presence.type_) - .append_all(presence.show.into_iter()) + .append_all(presence.show) .append_all(presence.statuses.into_iter().map(|(lang, status)| { Element::builder("status", ns::DEFAULT_NS) .attr( @@ -370,7 +365,7 @@ impl From for Element { .append(format!("{}", presence.priority)), ) }) - .append_all(presence.payloads.into_iter()) + .append_all(presence.payloads) .build() } } diff --git a/parsers/src/pubsub/event.rs b/parsers/src/pubsub/event.rs index aa3b706..7ce13c6 100644 --- a/parsers/src/pubsub/event.rs +++ b/parsers/src/pubsub/event.rs @@ -209,7 +209,7 @@ impl From for Element { PubSubEvent::PublishedItems { node, items } => { Element::builder("items", ns::PUBSUB_EVENT) .attr("node", node) - .append_all(items.into_iter()) + .append_all(items) } PubSubEvent::RetractedItems { node, items } => { Element::builder("items", ns::PUBSUB_EVENT) diff --git a/parsers/src/pubsub/mod.rs b/parsers/src/pubsub/mod.rs index 008d7a0..fcbb569 100644 --- a/parsers/src/pubsub/mod.rs +++ b/parsers/src/pubsub/mod.rs @@ -11,6 +11,7 @@ pub mod event; pub mod owner; /// The `http://jabber.org/protocol/pubsub` protocol. +#[allow(clippy::module_inception)] pub mod pubsub; pub use self::event::PubSubEvent; diff --git a/parsers/src/rtt.rs b/parsers/src/rtt.rs index 89a288b..b8fa6a5 100644 --- a/parsers/src/rtt.rs +++ b/parsers/src/rtt.rs @@ -151,9 +151,9 @@ impl TryFrom for Action { fn try_from(elem: Element) -> Result { match elem.name() { - "t" => Insert::try_from(elem).map(|insert| Action::Insert(insert)), - "e" => Erase::try_from(elem).map(|erase| Action::Erase(erase)), - "w" => Wait::try_from(elem).map(|wait| Action::Wait(wait)), + "t" => Insert::try_from(elem).map(Action::Insert), + "e" => Erase::try_from(elem).map(Action::Erase), + "w" => Wait::try_from(elem).map(Action::Wait), _ => Err(Error::ParseError("This is not a rtt action element.")), } } diff --git a/parsers/src/util/helpers.rs b/parsers/src/util/helpers.rs index cdf4689..ff30993 100644 --- a/parsers/src/util/helpers.rs +++ b/parsers/src/util/helpers.rs @@ -76,7 +76,7 @@ impl WhitespaceAwareBase64 { .chars() .filter(|ch| *ch != ' ' && *ch != '\n' && *ch != '\t') .collect(); - Ok(Base64Engine.decode(&s)?) + Ok(Base64Engine.decode(s)?) } pub fn encode(b: &[u8]) -> Option { diff --git a/parsers/src/xhtml.rs b/parsers/src/xhtml.rs index 6d30255..2658064 100644 --- a/parsers/src/xhtml.rs +++ b/parsers/src/xhtml.rs @@ -23,19 +23,18 @@ pub struct XhtmlIm { impl XhtmlIm { /// Serialise formatted text to HTML. - pub fn to_html(self) -> String { + pub fn into_html(self) -> String { let mut html = Vec::new(); // TODO: use the best language instead. - for (lang, body) in self.bodies { + if let Some((lang, body)) = self.bodies.into_iter().next() { if lang.is_empty() { assert!(body.xml_lang.is_none()); } else { assert_eq!(Some(lang), body.xml_lang); } for tag in body.children { - html.push(tag.to_html()); + html.push(tag.into_html()); } - break; } html.concat() } @@ -112,9 +111,9 @@ enum Child { } impl Child { - fn to_html(self) -> String { + fn into_html(self) -> String { match self { - Child::Tag(tag) => tag.to_html(), + Child::Tag(tag) => tag.into_html(), Child::Text(text) => text, } } @@ -227,7 +226,7 @@ enum Tag { } impl Tag { - fn to_html(self) -> String { + fn into_html(self) -> String { match self { Tag::A { href, @@ -468,7 +467,7 @@ fn children_to_nodes(children: Vec) -> impl IntoIterator { fn children_to_html(children: Vec) -> String { children .into_iter() - .map(|child| child.to_html()) + .map(|child| child.into_html()) .collect::>() .concat() } @@ -592,7 +591,7 @@ mod tests { .unwrap(); let parsed = XhtmlIm::try_from(elem).unwrap(); let parsed2 = parsed.clone(); - let html = parsed.to_html(); + let html = parsed.into_html(); assert_eq!(html, "Hello world!"); let elem = Element::from(parsed2); @@ -605,14 +604,14 @@ mod tests { .parse() .unwrap(); let xhtml_im = XhtmlIm::try_from(elem).unwrap(); - let html = xhtml_im.to_html(); + let html = xhtml_im.into_html(); assert_eq!(html, "

Hello world!

"); let elem: Element = "

Hello world!

" .parse() .unwrap(); let xhtml_im = XhtmlIm::try_from(elem).unwrap(); - let html = xhtml_im.to_html(); + let html = xhtml_im.into_html(); assert_eq!(html, "

Hello world!

"); }