Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Feb 11, 2019
1 parent d9554d4 commit a3dc71d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/lib.rs
Expand Up @@ -50,6 +50,11 @@ pub enum ViewMode {
Decade,
}

/// A callback taking a date as parameter.
///
/// This is an internal type used to improve readability.
type DateCallback<T> = Rc<Fn(&mut Cursive, &Date<T>)>;

/// View for selecting a date, supporting different modes for day, month or
/// year based selection.
///
Expand Down Expand Up @@ -90,8 +95,8 @@ pub struct CalendarView<T: TimeZone, L: Locale> {
earliest_date: Option<Date<T>>,
latest_date: Option<Date<T>>,
date: Date<T>,
on_submit: Option<Rc<Fn(&mut Cursive, &Date<T>)>>,
on_select: Option<Rc<Fn(&mut Cursive, &Date<T>)>>,
on_submit: Option<DateCallback<T>>,
on_select: Option<DateCallback<T>>,

size: Vec2,

Expand Down
16 changes: 8 additions & 8 deletions src/month.rs
@@ -1,5 +1,5 @@
/// Enumeration of all months in a year.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum Month {
/// The month of January.
January,
Expand Down Expand Up @@ -29,14 +29,14 @@ pub enum Month {

impl Month {
#[doc(hidden)]
pub fn prev(&self) -> Self {
pub fn prev(self) -> Self {
let index: i32 = self.into();
MONTH_LIST[(((index - 1) + 12) % 12) as usize]
}

#[doc(hidden)]
pub fn number_of_days(&self, year: i32) -> i32 {
match *self {
pub fn number_of_days(self, year: i32) -> i32 {
match self {
Month::February => {
if (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 {
29
Expand All @@ -56,8 +56,8 @@ impl Month {
}

#[doc(hidden)]
pub fn prev_number_of_days(&self, year: i32) -> i32 {
match *self {
pub fn prev_number_of_days(self, year: i32) -> i32 {
match self {
Month::January => self.prev().number_of_days(year - 1),
_ => self.prev().number_of_days(year),
}
Expand Down Expand Up @@ -87,9 +87,9 @@ impl From<u32> for Month {
}
}

impl<'a> Into<i32> for &'a Month {
impl<'a> Into<i32> for Month {
fn into(self) -> i32 {
match *self {
match self {
Month::January => 0,
Month::February => 1,
Month::March => 2,
Expand Down

0 comments on commit a3dc71d

Please sign in to comment.