summaryrefslogtreecommitdiff
path: root/src/year.rs
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2022-03-16 14:52:31 -0400
committerBotahamec <botahamec@outlook.com>2022-03-16 14:52:31 -0400
commite0e0a18a4bc873583e973d771669e88a92b20d92 (patch)
treeba060d810c4621ec7e489afb19ad180a6b2ab755 /src/year.rs
parent5ca69f1830763b689bae9c4873a2912b3f1e23b1 (diff)
parent954cfd1385709d41ef0ece9c78b8dcee236f55e4 (diff)
Merge branch 'master' of https://github.com/botahamec/botic
Diffstat (limited to 'src/year.rs')
-rw-r--r--src/year.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/year.rs b/src/year.rs
index 284821c..c2d86ce 100644
--- a/src/year.rs
+++ b/src/year.rs
@@ -23,6 +23,7 @@ impl Year {
/// const YEAR: Year = Year::from_i16(2021);
/// assert_eq!(2021, YEAR.as_i16());
/// ```
+ #[must_use]
pub const fn from_i16(i: i16) -> Self {
Self(i)
}
@@ -38,6 +39,7 @@ impl Year {
/// const YEAR_INT: i16 = YEAR.as_i16();
/// assert_eq!(2021, YEAR_INT);
/// ```
+ #[must_use]
pub const fn as_i16(self) -> i16 {
self.0
}
@@ -53,6 +55,7 @@ impl Year {
/// assert_eq!(Some(Year::from(2022)), Year::from_i16(2021).checked_add(1));
/// assert_eq!(None, Year::MAX.checked_add(1));
/// ```
+ #[must_use]
pub const fn checked_add(self, rhs: i16) -> Option<Year> {
match self.0.checked_add(rhs) {
Some(year) => Some(Self(year)),
@@ -74,6 +77,7 @@ impl Year {
/// assert_eq!((Year::from(2022), false), Year::from(2021).overflowing_add(1));
/// assert_eq!((Year::MIN, true), Year::MAX.overflowing_add(1));
/// ```
+ #[must_use]
pub const fn overflowing_add(self, rhs: i16) -> (Year, bool) {
let int_result = self.0.overflowing_add(rhs);
(Year(int_result.0), int_result.1)
@@ -90,6 +94,7 @@ impl Year {
/// assert_eq!(Year::from(2022), Year::from(2021).saturating_add(1));
/// assert_eq!(Year::MAX, Year::MAX.saturating_add(1));
/// ```
+ #[must_use]
pub const fn saturating_add(self, rhs: i16) -> Year {
Year(self.0.saturating_add(rhs))
}
@@ -104,6 +109,7 @@ impl Year {
///
/// assert_eq!(Year::from(2022), Year::from(2021).wrapping_add(1));
/// assert_eq!(Year::MIN, Year::MAX.wrapping_add(1));
+ #[must_use]
pub const fn wrapping_add(self, rhs: i16) -> Year {
Year(self.0.wrapping_add(rhs))
}
@@ -119,6 +125,7 @@ impl Year {
/// assert_eq!(Some(Year::from(2020)), Year::from_i16(2021).checked_sub(1));
/// assert_eq!(None, Year::MIN.checked_sub(1));
/// ```
+ #[must_use]
pub const fn checked_sub(self, rhs: i16) -> Option<Year> {
match self.0.checked_sub(rhs) {
Some(year) => Some(Self(year)),
@@ -140,6 +147,7 @@ impl Year {
/// assert_eq!((Year::from(2020), false), Year::from(2021).overflowing_sub(1));
/// assert_eq!((Year::MAX, true), Year::MIN.overflowing_sub(1));
/// ```
+ #[must_use]
pub const fn overflowing_sub(self, rhs: i16) -> (Year, bool) {
let int_result = self.0.overflowing_sub(rhs);
(Year(int_result.0), int_result.1)
@@ -156,6 +164,7 @@ impl Year {
/// assert_eq!(Year::from(2020), Year::from(2021).saturating_sub(1));
/// assert_eq!(Year::MIN, Year::MIN.saturating_sub(1));
/// ```
+ #[must_use]
pub const fn saturating_sub(self, rhs: i16) -> Year {
Year(self.0.saturating_sub(rhs))
}
@@ -170,6 +179,7 @@ impl Year {
///
/// assert_eq!(Year::from(2020), Year::from(2021).wrapping_sub(1));
/// assert_eq!(Year::MAX, Year::MIN.wrapping_sub(1));
+ #[must_use]
pub const fn wrapping_sub(self, rhs: i16) -> Year {
Year(self.0.wrapping_sub(rhs))
}
@@ -186,6 +196,7 @@ impl Year {
/// assert!(Year::from(2000).is_leap_year());
/// assert!(!Year::from(2100).is_leap_year());
/// ```
+ #[must_use]
pub const fn is_leap_year(self) -> bool {
(self.0 % 4 == 0) && ((self.0 % 100 != 0) || (self.0 % 400 == 0))
}
@@ -221,12 +232,12 @@ impl<I: Into<i16>> Sub<I> for Year {
impl AddAssign<i16> for Year {
fn add_assign(&mut self, rhs: i16) {
- self.0 = self.0 + rhs
+ self.0 = self.0 + rhs;
}
}
impl SubAssign<i16> for Year {
fn sub_assign(&mut self, rhs: i16) {
- self.0 = self.0 - rhs
+ self.0 = self.0 - rhs;
}
}