From 1b635854adf1e62dda2042c7a8ebeac7d7764166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 7 Apr 2025 21:53:22 +0200 Subject: [PATCH] parsers: clippy run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- 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(-) diff --git a/parsers/ChangeLog b/parsers/ChangeLog index cd5d4b54..47d79f2a 100644 --- a/parsers/ChangeLog +++ b/parsers/ChangeLog @@ -90,6 +90,7 @@ XXXX-YY-ZZ RELEASER - 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 diff --git a/parsers/src/date.rs b/parsers/src/date.rs index 8a488ad6..dd5f99f9 100644 --- a/parsers/src/date.rs +++ b/parsers/src/date.rs @@ -19,7 +19,7 @@ pub struct Xep0082; impl TextCodec> for Xep0082 { fn decode(&self, s: String) -> Result, 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>( diff --git a/parsers/src/http_upload.rs b/parsers/src/http_upload.rs index fb276fd5..47770b16 100644 --- a/parsers/src/http_upload.rs +++ b/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()) + )) } }) } diff --git a/parsers/src/iq.rs b/parsers/src/iq.rs index edca5bb1..6caff133 100644 --- a/parsers/src/iq.rs +++ b/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 { Some( match *self { diff --git a/parsers/src/stream_error.rs b/parsers/src/stream_error.rs index b4c97155..ad2f1500 100644 --- a/parsers/src/stream_error.rs +++ b/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 { ::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(()) } diff --git a/parsers/src/time.rs b/parsers/src/time.rs index 73a35980..9092512d 100644 --- a/parsers/src/time.rs +++ b/parsers/src/time.rs @@ -19,7 +19,7 @@ struct ColonSeparatedOffset; impl TextCodec for ColonSeparatedOffset { fn decode(&self, s: String) -> Result { - 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>, Error> { @@ -69,7 +69,7 @@ impl From for DateTime { impl From for DateTime { fn from(time: TimeResult) -> Self { - time.utc.into() + time.utc } } @@ -77,10 +77,7 @@ impl From> for TimeResult { fn from(dt: DateTime) -> 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> for TimeResult { fn from(dt: DateTime) -> Self { TimeResult { tz_offset: FixedOffset::east_opt(0).unwrap(), - utc: dt.into(), + utc: dt, } } } diff --git a/parsers/src/tune.rs b/parsers/src/tune.rs index d27cf5eb..1441b3ae 100644 --- a/parsers/src/tune.rs +++ b/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::*; diff --git a/parsers/src/xhtml.rs b/parsers/src/xhtml.rs index 28cd3064..bc7bb869 100644 --- a/parsers/src/xhtml.rs +++ b/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());