From 761a1e7653357d8e769ebf9cda66ab62b3d8ed0e Mon Sep 17 00:00:00 2001 From: Hendrik Sollich Date: Mon, 29 Apr 2024 22:39:04 +0200 Subject: [PATCH] refactor: fix new lints --- Cargo.toml | 2 +- examples/full_circle.rs | 1 - src/calendar.rs | 6 +++--- src/components.rs | 4 ++-- src/components/alarm.rs | 17 ++++++++--------- src/components/date_time.rs | 6 +++--- src/components/todo.rs | 1 - src/parser/components.rs | 2 +- src/parser/parsed_string.rs | 6 +++--- src/parser/properties.rs | 2 +- src/properties.rs | 2 +- tests/try_into_string.rs | 1 - 12 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5f38585..66884bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ chrono-tz = {version = "0.8", optional = true } [dependencies.chrono] version = "0.4" -default_features = false +default-features = false features = ["clock", "std", "wasmbind"] [dependencies.nom] diff --git a/examples/full_circle.rs b/examples/full_circle.rs index 8cc46e1..4f81b8f 100644 --- a/examples/full_circle.rs +++ b/examples/full_circle.rs @@ -2,7 +2,6 @@ use std::str::FromStr; use chrono::*; -use icalendar::parser; use icalendar::*; fn main() { diff --git a/src/calendar.rs b/src/calendar.rs index 57cbfb1..6c6e8d2 100644 --- a/src/calendar.rs +++ b/src/calendar.rs @@ -1,5 +1,5 @@ use chrono::Duration; -use std::{fmt, iter::FromIterator, mem, ops::Deref}; +use std::{fmt, mem, ops::Deref}; use crate::{components::*, Parameter, Property}; @@ -232,7 +232,7 @@ impl fmt::Display for Calendar { } impl TryInto for &Calendar { - type Error = std::fmt::Error; + type Error = fmt::Error; fn try_into(self) -> Result { let mut out_string = String::new(); self.fmt_write(&mut out_string)?; @@ -279,7 +279,7 @@ impl> FromIterator for Calendar { } #[test] fn from_adds_default_properties() { - let todo = crate::Todo::default(); + let todo = Todo::default(); let cal = Calendar::from([todo]); assert!(cal.property_value("VERSION").is_some()); assert!(cal.property_value("CALSCALE").is_some()); diff --git a/src/components.rs b/src/components.rs index 84ec7f8..7de71f8 100644 --- a/src/components.rs +++ b/src/components.rs @@ -129,7 +129,7 @@ pub trait Component { } /// Serializes this component into [`rfc5545`](http://tools.ietf.org/html/rfc5545) again - fn try_into_string(&self) -> Result { + fn try_into_string(&self) -> Result { let mut out_string = String::new(); self.fmt_write(&mut out_string)?; Ok(out_string) @@ -185,7 +185,7 @@ pub trait Component { /// /// Ranges from 0 to 10, larger values will be truncated fn priority(&mut self, priority: u32) -> &mut Self { - let priority = ::std::cmp::min(priority, 10); + let priority = std::cmp::min(priority, 10); self.add_property("PRIORITY", &priority.to_string()) } diff --git a/src/components/alarm.rs b/src/components/alarm.rs index 2b8cae9..e978789 100644 --- a/src/components/alarm.rs +++ b/src/components/alarm.rs @@ -282,7 +282,7 @@ fn test_email() { pub mod properties { - use crate::components::{alarm::properties::Parameter, date_time::parse_duration}; + use crate::components::date_time::parse_duration; use super::*; @@ -316,14 +316,13 @@ pub mod properties { } } - impl ToString for Action { - /// convert the ACTION into its serialized representation - fn to_string(&self) -> String { + impl fmt::Display for Action { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Action::Audio => "AUDIO".into(), - Action::Email => "EMAIL".into(), - Action::Display => "DISPLAY".into(), - Action::Other(other) => other.clone(), + Action::Audio => write!(f, "AUDIO"), + Action::Email => write!(f, "EMAIL"), + Action::Display => write!(f, "DISPLAY"), + Action::Other(other) => write!(f, "{}", other), } } } @@ -411,7 +410,7 @@ pub mod properties { pub enum Trigger { /// Duration in relation to either Start or End of the event Duration(Duration, Option), - /// Absolute DateTime of the Trigger + /// Absolute `DateTime` of the Trigger DateTime(CalendarDateTime), } diff --git a/src/components/date_time.rs b/src/components/date_time.rs index 68966e0..62e0cf6 100644 --- a/src/components/date_time.rs +++ b/src/components/date_time.rs @@ -1,7 +1,7 @@ #![allow(dead_code, unused)] use std::str::FromStr; -use chrono::{Date, DateTime, Duration, NaiveDate, NaiveDateTime, Offset, TimeZone as _, Utc}; +use chrono::{DateTime, Duration, NaiveDate, NaiveDateTime, Offset, TimeZone as _, Utc}; use crate::{Property, ValueType}; @@ -299,8 +299,8 @@ impl From> for DatePerhapsTime { // } #[allow(deprecated)] -impl From> for DatePerhapsTime { - fn from(dt: Date) -> Self { +impl From> for DatePerhapsTime { + fn from(dt: chrono::Date) -> Self { Self::Date(dt.naive_utc()) } } diff --git a/src/components/todo.rs b/src/components/todo.rs index 841d3ed..dfdb6c4 100644 --- a/src/components/todo.rs +++ b/src/components/todo.rs @@ -1,6 +1,5 @@ use chrono::*; -use super::date_time::parse_utc_date_time; use super::*; /// VTODO [(RFC 5545, Section 3.6.2 )](https://tools.ietf.org/html/rfc5545#section-3.6.2) diff --git a/src/parser/components.rs b/src/parser/components.rs index a29dc6a..85624c3 100644 --- a/src/parser/components.rs +++ b/src/parser/components.rs @@ -170,7 +170,7 @@ impl FromStr for CalendarComponent { type Err = String; fn from_str(s: &str) -> Result { - let from_parsed = crate::CalendarComponent::from(read_component(&unfold(s))?); + let from_parsed = CalendarComponent::from(read_component(&unfold(s))?); Ok(from_parsed) } } diff --git a/src/parser/parsed_string.rs b/src/parser/parsed_string.rs index f98fd85..3ddcc1d 100644 --- a/src/parser/parsed_string.rs +++ b/src/parser/parsed_string.rs @@ -53,9 +53,9 @@ impl From for ParseString<'static> { } } -impl ToString for ParseString<'_> { - fn to_string(&self) -> String { - self.to_owned().into() +impl std::fmt::Display for ParseString<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) } } diff --git a/src/parser/properties.rs b/src/parser/properties.rs index 321b5cd..48c01eb 100644 --- a/src/parser/properties.rs +++ b/src/parser/properties.rs @@ -119,7 +119,7 @@ impl FromStr for crate::Property { type Err = String; fn from_str(s: &str) -> Result { - Ok(crate::parser::Property::try_from(s)?.into()) + Ok(Property::try_from(s)?.into()) } } diff --git a/src/properties.rs b/src/properties.rs index 0400879..6db3e82 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -156,7 +156,7 @@ impl Property { } impl TryInto for Property { - type Error = std::fmt::Error; + type Error = fmt::Error; fn try_into(self) -> Result { let mut out_string = String::new(); diff --git a/tests/try_into_string.rs b/tests/try_into_string.rs index 4d21b09..c90fc8f 100644 --- a/tests/try_into_string.rs +++ b/tests/try_into_string.rs @@ -1,6 +1,5 @@ use chrono::*; use icalendar::*; -use std::convert::TryInto; #[test] fn try_into_string() -> Result<(), Box> {