aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/event.rs8
-rw-r--r--src/model/repetition.rs2
2 files changed, 5 insertions, 5 deletions
diff --git a/src/model/event.rs b/src/model/event.rs
index b18d811..249d077 100644
--- a/src/model/event.rs
+++ b/src/model/event.rs
@@ -46,16 +46,16 @@ impl Event {
/// Repeated events in an included date range
pub fn repetitions_between(
- events: &Vec<Event>,
+ events: &[Event],
start: NaiveDate,
end: NaiveDate,
) -> HashMap<NaiveDate, Vec<Event>> {
let mut res: HashMap<NaiveDate, Vec<Event>> = HashMap::new();
for event in events {
- for repetition in event.repetition.as_ref() {
+ if let Some(repetition) = &event.repetition {
for date in repetition.between(event.date, start, end) {
- res.entry(date).or_insert(vec![]).push(event.clone())
+ res.entry(date).or_insert_with(Vec::new).push(event.clone())
}
}
}
@@ -117,7 +117,7 @@ fn validate_time(time: String) -> Option<Option<NaiveTime>> {
if time.is_empty() {
Some(None)
} else {
- parse_time(time).map(|t| Some(t))
+ parse_time(time).map(Some)
}
}
diff --git a/src/model/repetition.rs b/src/model/repetition.rs
index ceb903b..d21dd70 100644
--- a/src/model/repetition.rs
+++ b/src/model/repetition.rs
@@ -16,7 +16,7 @@ pub enum DayOfMonth {
pub fn validate_day(str: &str) -> Option<u8> {
let n = str.parse::<u8>().ok()?;
- if n >= 1 && n <= 31 {
+ if (1..=31).contains(&n) {
Some(n)
} else {
None