Skip to content

Commit

Permalink
Solve linting warnings (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelmello authored Mar 10, 2024
1 parent 62dfcb9 commit eee91f7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
20 changes: 16 additions & 4 deletions inquire/src/prompts/dateselect/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,22 @@ where

fn handle(&mut self, action: DateSelectPromptAction) -> InquireResult<ActionResult> {
let result = match action {
DateSelectPromptAction::GoToPrevWeek => self.shift_date(Duration::weeks(-1)),
DateSelectPromptAction::GoToNextWeek => self.shift_date(Duration::weeks(1)),
DateSelectPromptAction::GoToPrevDay => self.shift_date(Duration::days(-1)),
DateSelectPromptAction::GoToNextDay => self.shift_date(Duration::days(1)),
DateSelectPromptAction::GoToPrevWeek => self.shift_date(
Duration::try_weeks(-1)
.expect("unexpected overflow when calculating duration of 1 week"),
),
DateSelectPromptAction::GoToNextWeek => self.shift_date(
Duration::try_weeks(1)
.expect("unexpected overflow when calculating duration of 1 week"),
),
DateSelectPromptAction::GoToPrevDay => self.shift_date(
Duration::try_days(-1)
.expect("unexpected overflow when calculating duration of 1 day"),
),
DateSelectPromptAction::GoToNextDay => self.shift_date(
Duration::try_days(1)
.expect("unexpected overflow when calculating duration of 1 day"),
),
DateSelectPromptAction::GoToPrevYear => self.shift_months(-12),
DateSelectPromptAction::GoToNextYear => self.shift_months(12),
DateSelectPromptAction::GoToPrevMonth => self.shift_months(-1),
Expand Down
4 changes: 3 additions & 1 deletion inquire/src/ui/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ pub mod date {
let mut date_it = get_start_date(month, year);
// first date of week-line is possibly in the previous month
if date_it.weekday() == week_start {
date_it = date_it.sub(Duration::weeks(1));
date_it = date_it.sub(
Duration::try_weeks(1).expect("overflow when calculating duration of 1 week"),
);
} else {
while date_it.weekday() != week_start {
date_it = match date_it.pred_opt() {
Expand Down
24 changes: 12 additions & 12 deletions inquire/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ where
len
}

impl<'a, T> Debug for Page<'a, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Page")
.field("first", &self.first)
.field("last", &self.last)
.field("content", &format!("({} elements)", &self.content.len()))
.field("cursor", &self.cursor)
.field("total", &self.total)
.finish()
}
}

#[cfg(test)]
mod test {
#![allow(clippy::bool_assert_comparison)]
Expand Down Expand Up @@ -249,15 +261,3 @@ mod test {
assert_eq!(6, page.total);
}
}

impl<'a, T> Debug for Page<'a, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Page")
.field("first", &self.first)
.field("last", &self.last)
.field("content", &format!("({} elements)", &self.content.len()))
.field("cursor", &self.cursor)
.field("total", &self.total)
.finish()
}
}

0 comments on commit eee91f7

Please sign in to comment.