Lots of clippy appeasement

This commit is contained in:
Lennart
2025-10-27 20:12:21 +01:00
parent 0d071d3b92
commit 86cf490fa9
84 changed files with 413 additions and 435 deletions

View File

@@ -15,7 +15,8 @@ pub struct EventObject {
}
impl EventObject {
#[must_use] pub fn get_uid(&self) -> &str {
#[must_use]
pub fn get_uid(&self) -> &str {
self.event.get_uid()
}
@@ -70,9 +71,9 @@ impl EventObject {
for prop in &self.event.properties {
rrule_set = match prop.name.as_str() {
"RRULE" => {
let rrule = RRule::from_str(prop.value.as_ref().ok_or(Error::RRuleError(
rrule::ParseError::MissingDateGenerationRules.into(),
))?)?
let rrule = RRule::from_str(prop.value.as_ref().ok_or_else(|| {
Error::RRuleError(rrule::ParseError::MissingDateGenerationRules.into())
})?)?
.validate(dtstart)
.unwrap();
rrule_set.rrule(rrule)
@@ -120,8 +121,8 @@ impl EventObject {
date.format()
};
for _override in overrides {
if let Some(override_id) = &_override
for ev_override in overrides {
if let Some(override_id) = &ev_override
.event
.get_recurrence_id()
.as_ref()
@@ -131,7 +132,7 @@ impl EventObject {
{
// We have an override for this occurence
//
events.push(_override.event.clone());
events.push(ev_override.event.clone());
continue 'recurrence;
}
}
@@ -185,7 +186,7 @@ mod tests {
use crate::CalendarObject;
use ical::generator::Emitter;
const ICS: &str = r#"BEGIN:VCALENDAR
const ICS: &str = r"BEGIN:VCALENDAR
CALSCALE:GREGORIAN
VERSION:2.0
BEGIN:VTIMEZONE
@@ -203,7 +204,7 @@ SUMMARY:weekly stuff
TRANSP:OPAQUE
RRULE:FREQ=WEEKLY;COUNT=4;INTERVAL=2;BYDAY=TU,TH,SU
END:VEVENT
END:VCALENDAR"#;
END:VCALENDAR";
const EXPANDED: [&str; 4] = [
"BEGIN:VEVENT\r
@@ -251,13 +252,7 @@ END:VEVENT\r\n",
#[test]
fn test_expand_recurrence() {
let event = CalendarObject::from_ics(ICS.to_string()).unwrap();
let (event, overrides) = if let crate::CalendarObjectComponent::Event(
main_event,
overrides,
) = event.get_data()
{
(main_event, overrides)
} else {
let crate::CalendarObjectComponent::Event(event, overrides) = event.get_data() else {
panic!()
};

View File

@@ -26,7 +26,8 @@ pub enum CalendarObjectType {
}
impl CalendarObjectType {
#[must_use] pub const fn as_str(&self) -> &'static str {
#[must_use]
pub const fn as_str(&self) -> &'static str {
match self {
Self::Event => "VEVENT",
Self::Todo => "VTODO",
@@ -208,15 +209,18 @@ impl CalendarObject {
})
}
#[must_use] pub const fn get_vtimezones(&self) -> &HashMap<String, IcalTimeZone> {
#[must_use]
pub const fn get_vtimezones(&self) -> &HashMap<String, IcalTimeZone> {
&self.vtimezones
}
#[must_use] pub const fn get_data(&self) -> &CalendarObjectComponent {
#[must_use]
pub const fn get_data(&self) -> &CalendarObjectComponent {
&self.data
}
#[must_use] pub fn get_id(&self) -> &str {
#[must_use]
pub fn get_id(&self) -> &str {
match &self.data {
// We've made sure before that the first component exists and all components share the
// same UID
@@ -226,22 +230,26 @@ impl CalendarObject {
}
}
#[must_use] pub fn get_etag(&self) -> String {
#[must_use]
pub fn get_etag(&self) -> String {
let mut hasher = Sha256::new();
hasher.update(self.get_id());
hasher.update(self.get_ics());
format!("\"{:x}\"", hasher.finalize())
}
#[must_use] pub fn get_ics(&self) -> &str {
#[must_use]
pub fn get_ics(&self) -> &str {
&self.ics
}
#[must_use] pub fn get_component_name(&self) -> &str {
#[must_use]
pub fn get_component_name(&self) -> &str {
self.get_object_type().as_str()
}
#[must_use] pub fn get_object_type(&self) -> CalendarObjectType {
#[must_use]
pub fn get_object_type(&self) -> CalendarObjectType {
(&self.data).into()
}
@@ -249,7 +257,7 @@ impl CalendarObject {
match &self.data {
CalendarObjectComponent::Event(main_event, overrides) => Ok(overrides
.iter()
.chain([main_event].into_iter())
.chain(std::iter::once(main_event))
.map(super::event::EventObject::get_dtstart)
.collect::<Result<Vec<_>, _>>()?
.into_iter()
@@ -263,7 +271,7 @@ impl CalendarObject {
match &self.data {
CalendarObjectComponent::Event(main_event, overrides) => Ok(overrides
.iter()
.chain([main_event].into_iter())
.chain(std::iter::once(main_event))
.map(super::event::EventObject::get_last_occurence)
.collect::<Result<Vec<_>, _>>()?
.into_iter()