From b3f129bae368c49688e964e07c4680daa9e77116 Mon Sep 17 00:00:00 2001 From: lukas Date: Fri, 31 Mar 2023 14:52:11 +0200 Subject: [PATCH] Add #[must_use] to some methods --- src/naive/date.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/naive/date.rs b/src/naive/date.rs index 92739401a4..e9e3f22c9d 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -469,6 +469,7 @@ impl NaiveDate { /// /// Returns `None` if `n` out-of-range; ie. if `n` is larger than the number of `weekday` in /// `month` (eg. the 6th Friday of March 2017), or if `n == 0`. + #[must_use] pub fn from_weekday_of_month_opt( year: i32, month: u32, @@ -549,6 +550,7 @@ impl NaiveDate { /// Some(NaiveDate::from_ymd_opt(2022, 9, 30).unwrap()) /// ); /// ``` + #[must_use] pub fn checked_add_months(self, months: Months) -> Option { if months.0 == 0 { return Some(self); @@ -579,6 +581,7 @@ impl NaiveDate { /// None /// ); /// ``` + #[must_use] pub fn checked_sub_months(self, months: Months) -> Option { if months.0 == 0 { return Some(self); @@ -591,6 +594,7 @@ impl NaiveDate { } } + #[must_use] fn diff_months(self, months: i32) -> Option { let (years, left) = ((months / 12), (months % 12)); @@ -652,6 +656,7 @@ impl NaiveDate { /// None /// ); /// ``` + #[must_use] pub fn checked_add_days(self, days: Days) -> Option { if days.0 == 0 { return Some(self); @@ -675,6 +680,7 @@ impl NaiveDate { /// None /// ); /// ``` + #[must_use] pub fn checked_sub_days(self, days: Days) -> Option { if days.0 == 0 { return Some(self); @@ -683,6 +689,7 @@ impl NaiveDate { i64::try_from(days.0).ok().and_then(|d| self.diff_days(-d)) } + #[must_use] fn diff_days(self, days: i64) -> Option { let secs = days.checked_mul(86400)?; // 86400 seconds in one day if secs >= core::i64::MAX / 1000 || secs <= core::i64::MIN / 1000 { @@ -706,6 +713,7 @@ impl NaiveDate { /// assert_eq!(dt.time(), t); /// ``` #[inline] + #[must_use] pub const fn and_time(&self, time: NaiveTime) -> NaiveDateTime { NaiveDateTime::new(*self, time) }