parsers: clippy run

Maxime “pep” Buquet created

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>

Change summary

parsers/ChangeLog           |  1 +
parsers/src/date.rs         |  2 +-
parsers/src/http_upload.rs  |  3 +--
parsers/src/iq.rs           |  2 +-
parsers/src/stream_error.rs | 14 +++++---------
parsers/src/time.rs         | 11 ++++-------
parsers/src/tune.rs         |  6 ++++++
parsers/src/xhtml.rs        |  2 ++
8 files changed, 21 insertions(+), 20 deletions(-)

Detailed changes

parsers/ChangeLog 🔗

@@ -90,6 +90,7 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
       - Add Message::get_best_body_cloned and Message::get_best_subject_cloned
         to clone automatically when performance is not an issue (!497)
       - Fix compatibility to uuid 1.12
+      - Implement Default for Tune
 
 Version 0.21.0:
 2024-07-25 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>

parsers/src/date.rs 🔗

@@ -19,7 +19,7 @@ pub struct Xep0082;
 
 impl TextCodec<ChronoDateTime<FixedOffset>> for Xep0082 {
     fn decode(&self, s: String) -> Result<ChronoDateTime<FixedOffset>, Error> {
-        Ok(ChronoDateTime::parse_from_rfc3339(&s).map_err(Error::text_parse_error)?)
+        ChronoDateTime::parse_from_rfc3339(&s).map_err(Error::text_parse_error)
     }
 
     fn encode<'x>(

parsers/src/http_upload.rs 🔗

@@ -63,8 +63,7 @@ impl FromXmlText for HeaderName {
             _ => {
                 return Err(Error::Other(
                     "Header name must be either 'Authorization', 'Cookie', or 'Expires'.",
-                )
-                .into())
+                ))
             }
         })
     }

parsers/src/iq.rs 🔗

@@ -37,7 +37,7 @@ pub enum IqType {
     Error(StanzaError),
 }
 
-impl<'a> IntoAttributeValue for &'a IqType {
+impl IntoAttributeValue for &IqType {
     fn into_attribute_value(self) -> Option<String> {
         Some(
             match *self {

parsers/src/stream_error.rs 🔗

@@ -320,15 +320,11 @@ pub struct StreamError {
 impl fmt::Display for StreamError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         <DefinedCondition as fmt::Display>::fmt(&self.condition, f)?;
-        match self.text {
-            Some((_, ref text)) => write!(f, " ({:?})", text)?,
-            None => (),
-        };
-        match self.application_specific.get(0) {
-            Some(cond) => {
-                f.write_str(&String::from(cond))?;
-            }
-            None => (),
+        if let Some((_, ref text)) = self.text {
+            write!(f, " ({:?})", text)?
+        }
+        if let Some(cond) = self.application_specific.first() {
+            f.write_str(&String::from(cond))?;
         }
         Ok(())
     }

parsers/src/time.rs 🔗

@@ -19,7 +19,7 @@ struct ColonSeparatedOffset;
 
 impl TextCodec<FixedOffset> for ColonSeparatedOffset {
     fn decode(&self, s: String) -> Result<FixedOffset, Error> {
-        Ok(FixedOffset::from_str(&s).map_err(Error::text_parse_error)?)
+        FixedOffset::from_str(&s).map_err(Error::text_parse_error)
     }
 
     fn encode<'x>(&self, value: &'x FixedOffset) -> Result<Option<Cow<'x, str>>, Error> {
@@ -69,7 +69,7 @@ impl From<TimeResult> for DateTime<FixedOffset> {
 
 impl From<TimeResult> for DateTime<Utc> {
     fn from(time: TimeResult) -> Self {
-        time.utc.into()
+        time.utc
     }
 }
 
@@ -77,10 +77,7 @@ impl From<DateTime<FixedOffset>> for TimeResult {
     fn from(dt: DateTime<FixedOffset>) -> Self {
         let tz_offset = *dt.offset();
         let utc = dt.with_timezone(&Utc);
-        TimeResult {
-            tz_offset,
-            utc: utc.into(),
-        }
+        TimeResult { tz_offset, utc }
     }
 }
 
@@ -88,7 +85,7 @@ impl From<DateTime<Utc>> for TimeResult {
     fn from(dt: DateTime<Utc>) -> Self {
         TimeResult {
             tz_offset: FixedOffset::east_opt(0).unwrap(),
-            utc: dt.into(),
+            utc: dt,
         }
     }
 }

parsers/src/tune.rs 🔗

@@ -114,6 +114,12 @@ impl Tune {
     }
 }
 
+impl Default for Tune {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;

parsers/src/xhtml.rs 🔗

@@ -25,6 +25,8 @@ impl XhtmlIm {
     pub fn into_html(self) -> String {
         let mut html = Vec::new();
         // TODO: use the best language instead.
+        // XXX: Remove this flag later when fixing the code below
+        #[allow(clippy::never_loop)]
         for (lang, body) in self.bodies {
             if lang.is_empty() {
                 assert!(body.xml_lang.is_none());