Struct nichi::Year

source ·
pub struct Year(pub u16);
Expand description

Any year from 0 to 65,535

Tuple Fields§

§0: u16

Implementations§

source§

impl Year

source

pub const MAX: Year = _

assert_eq!(Year::MAX, Year(u16::MAX));
source

pub const MIN: Year = _

assert_eq!(Year::MIN, Year(u16::MIN));
source

pub const fn is_leap_year(self) -> bool

assert!(!Year(2019).is_leap_year());
assert!(Year(2020).is_leap_year());
assert!(!Year(2023).is_leap_year());
assert!(Year(2024).is_leap_year());
source

pub const fn days_in_year(self) -> DaysInYear

// Non-leap year.
assert_eq!(Year(2019).days_in_year(), 365);
// Leap year.
assert_eq!(Year(2020).days_in_year(), 366);
source

pub const fn days_in_month(self, month: Month) -> Day

assert_eq!(
	Year(2019).days_in_month(Month::January),
	Day::ThirtyFirst,
);

assert_eq!(
	Year(2019).days_in_month(Month::April),
	Day::Thirtieth,
);

assert_eq!(
	Year(2019).days_in_month(Month::February),
	Day::TwentyEighth,
);

// Leap Year
assert_eq!(
	Year(2020).days_in_month(Month::February),
	Day::TwentyNinth,
);
source

pub const fn inner(self) -> u16

assert_eq!(Year(2000).inner(), 2000);
source

pub fn from_str(s: &str) -> Option<Self>

assert_eq!(Year::from_str("0").unwrap(),     Year(0));
assert_eq!(Year::from_str("2000").unwrap(),  Year(2000));
assert_eq!(Year::from_str("65535").unwrap(), Year(65535));

Methods from Deref<Target = u16>§

1.43.0 · source

pub const MIN: u16 = 0u16

1.43.0 · source

pub const MAX: u16 = 65_535u16

1.53.0 · source

pub const BITS: u32 = 16u32

Trait Implementations§

source§

impl Add for Year

§

type Output = Year

The resulting type after applying the + operator.
source§

fn add(self, rhs: Year) -> Year

Performs the + operation. Read more
source§

impl AddAssign for Year

source§

fn add_assign(&mut self, rhs: Year)

Performs the += operation. Read more
source§

impl<'__de> BorrowDecode<'__de> for Year

source§

fn borrow_decode<__D: BorrowDecoder<'__de>>( decoder: &mut __D ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
source§

impl Clone for Year

source§

fn clone(&self) -> Year

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Year

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Decode for Year

source§

fn decode<__D: Decoder>(decoder: &mut __D) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
source§

impl Default for Year

source§

fn default() -> Year

Returns the “default value” for a type. Read more
source§

impl Deref for Year

§

type Target = u16

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for Year

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'de> Deserialize<'de> for Year

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Year

source§

fn fmt(&self, _derive_more_display_formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Encode for Year

source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.
source§

impl From<&f32> for Year

source§

fn from(f: &f32) -> Self

Converts to this type from the input type.
source§

impl From<&f64> for Year

source§

fn from(f: &f64) -> Self

Converts to this type from the input type.
source§

impl From<&i128> for Year

source§

fn from(year: &i128) -> Self

Converts to this type from the input type.
source§

impl From<&i16> for Year

source§

fn from(year: &i16) -> Self

Converts to this type from the input type.
source§

impl From<&i32> for Year

source§

fn from(year: &i32) -> Self

Converts to this type from the input type.
source§

impl From<&i64> for Year

source§

fn from(year: &i64) -> Self

Converts to this type from the input type.
source§

impl From<&i8> for Year

source§

fn from(year: &i8) -> Self

Converts to this type from the input type.
source§

impl From<&isize> for Year

source§

fn from(year: &isize) -> Self

Converts to this type from the input type.
source§

impl From<&u128> for Year

source§

fn from(year: &u128) -> Self

Converts to this type from the input type.
source§

impl From<&u32> for Year

source§

fn from(year: &u32) -> Self

Converts to this type from the input type.
source§

impl From<&u64> for Year

source§

fn from(year: &u64) -> Self

Converts to this type from the input type.
source§

impl From<&u8> for Year

source§

fn from(year: &u8) -> Self

Converts to this type from the input type.
source§

impl From<&usize> for Year

source§

fn from(year: &usize) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Year

source§

fn from(f: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Year

source§

fn from(f: f64) -> Self

Converts to this type from the input type.
source§

impl From<i128> for Year

source§

fn from(year: i128) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Year

source§

fn from(year: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Year

source§

fn from(year: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Year

source§

fn from(year: i64) -> Self

Converts to this type from the input type.
source§

impl From<i8> for Year

source§

fn from(year: i8) -> Self

Converts to this type from the input type.
source§

impl From<isize> for Year

source§

fn from(year: isize) -> Self

Converts to this type from the input type.
source§

impl From<u128> for Year

source§

fn from(year: u128) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Year

source§

fn from(original: u16) -> Year

Converts to this type from the input type.
source§

impl From<u32> for Year

source§

fn from(year: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Year

source§

fn from(year: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Year

source§

fn from(year: u8) -> Self

Converts to this type from the input type.
source§

impl From<usize> for Year

source§

fn from(year: usize) -> Self

Converts to this type from the input type.
source§

impl Hash for Year

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Into<i128> for Year

source§

fn into(self) -> i128

Converts this type into the (usually inferred) input type.
source§

impl Into<i16> for Year

source§

fn into(self) -> i16

Converts this type into the (usually inferred) input type.
source§

impl Into<i32> for Year

source§

fn into(self) -> i32

Converts this type into the (usually inferred) input type.
source§

impl Into<i64> for Year

source§

fn into(self) -> i64

Converts this type into the (usually inferred) input type.
source§

impl Into<i8> for Year

source§

fn into(self) -> i8

Converts this type into the (usually inferred) input type.
source§

impl Into<isize> for Year

source§

fn into(self) -> isize

Converts this type into the (usually inferred) input type.
source§

impl Into<u128> for Year

source§

fn into(self) -> u128

Converts this type into the (usually inferred) input type.
source§

impl Into<u16> for Year

source§

fn into(self) -> u16

Converts this type into the (usually inferred) input type.
source§

impl Into<u32> for Year

source§

fn into(self) -> u32

Converts this type into the (usually inferred) input type.
source§

impl Into<u64> for Year

source§

fn into(self) -> u64

Converts this type into the (usually inferred) input type.
source§

impl Into<u8> for Year

source§

fn into(self) -> u8

Converts this type into the (usually inferred) input type.
source§

impl Into<usize> for Year

source§

fn into(self) -> usize

Converts this type into the (usually inferred) input type.
source§

impl<__RhsT> Mul<__RhsT> for Year
where u16: Mul<__RhsT, Output = u16>,

§

type Output = Year

The resulting type after applying the * operator.
source§

fn mul(self, rhs: __RhsT) -> Year

Performs the * operation. Read more
source§

impl<__RhsT> MulAssign<__RhsT> for Year
where u16: MulAssign<__RhsT>,

source§

fn mul_assign(&mut self, rhs: __RhsT)

Performs the *= operation. Read more
source§

impl Not for Year

§

type Output = Year

The resulting type after applying the ! operator.
source§

fn not(self) -> Year

Performs the unary ! operation. Read more
source§

impl Ord for Year

source§

fn cmp(&self, other: &Year) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<i128> for Year

source§

fn eq(&self, other: &i128) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i16> for Year

source§

fn eq(&self, other: &i16) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i32> for Year

source§

fn eq(&self, other: &i32) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i64> for Year

source§

fn eq(&self, other: &i64) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i8> for Year

source§

fn eq(&self, other: &i8) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<isize> for Year

source§

fn eq(&self, other: &isize) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u128> for Year

source§

fn eq(&self, other: &u128) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u16> for Year

source§

fn eq(&self, other: &u16) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u32> for Year

source§

fn eq(&self, other: &u32) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u64> for Year

source§

fn eq(&self, other: &u64) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u8> for Year

source§

fn eq(&self, other: &u8) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<usize> for Year

source§

fn eq(&self, other: &usize) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Year

source§

fn eq(&self, other: &Year) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Year

source§

fn partial_cmp(&self, other: &Year) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Year

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Sum for Year

source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl Copy for Year

source§

impl Eq for Year

source§

impl StructuralEq for Year

source§

impl StructuralPartialEq for Year

Auto Trait Implementations§

§

impl RefUnwindSafe for Year

§

impl Send for Year

§

impl Sync for Year

§

impl Unpin for Year

§

impl UnwindSafe for Year

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,