Enum Weekday

Source
#[repr(u8)]
pub enum Weekday { Sunday = 1, Monday = 2, Tuesday = 3, Wednesday = 4, Thursday = 5, Friday = 6, Saturday = 7, }
Expand description

Day of the week

Variants§

§

Sunday = 1

§

Monday = 2

§

Tuesday = 3

§

Wednesday = 4

§

Thursday = 5

§

Friday = 6

§

Saturday = 7

Implementations§

Source§

impl Weekday

Source

pub const FIRST: Weekday = Weekday::Sunday

assert_eq!(Weekday::FIRST, Weekday::Sunday);
Source

pub const LAST: Weekday = Weekday::Saturday

assert_eq!(Weekday::LAST, Weekday::Saturday);
Source

pub const ALL: [Weekday; 7]

assert_eq!(Weekday::ALL[0], Weekday::Sunday);
assert_eq!(Weekday::ALL[1], Weekday::Monday);
assert_eq!(Weekday::ALL[2], Weekday::Tuesday);
assert_eq!(Weekday::ALL[3], Weekday::Wednesday);
assert_eq!(Weekday::ALL[4], Weekday::Thursday);
assert_eq!(Weekday::ALL[5], Weekday::Friday);
assert_eq!(Weekday::ALL[6], Weekday::Saturday);
Source

pub const fn new(weekday: u8) -> Self

assert_eq!(Weekday::new(1), Weekday::Sunday);
assert_eq!(Weekday::new(2), Weekday::Monday);
assert_eq!(Weekday::new(3), Weekday::Tuesday);
assert_eq!(Weekday::new(4), Weekday::Wednesday);
assert_eq!(Weekday::new(5), Weekday::Thursday);
assert_eq!(Weekday::new(6), Weekday::Friday);
assert_eq!(Weekday::new(7), Weekday::Saturday);
Weekday::new(0);
Weekday::new(8);
Source

pub const unsafe fn new_unchecked(weekday: u8) -> Self

unsafe {
	assert_eq!(Weekday::new_unchecked(1), Weekday::Sunday);
	assert_eq!(Weekday::new_unchecked(2), Weekday::Monday);
	assert_eq!(Weekday::new_unchecked(3), Weekday::Tuesday);
	assert_eq!(Weekday::new_unchecked(4), Weekday::Wednesday);
	assert_eq!(Weekday::new_unchecked(5), Weekday::Thursday);
	assert_eq!(Weekday::new_unchecked(6), Weekday::Friday);
	assert_eq!(Weekday::new_unchecked(7), Weekday::Saturday);
}
§Safety

weekday must be 1..=7.

// ⚠️ Undefined behavior.
// Will panic on debug.
unsafe { Weekday::new_unchecked(8) };
Source

pub const fn inner(self) -> u8

assert_eq!(Weekday::Sunday.inner(),    1);
assert_eq!(Weekday::Monday.inner(),    2);
assert_eq!(Weekday::Tuesday.inner(),   3);
assert_eq!(Weekday::Wednesday.inner(), 4);
assert_eq!(Weekday::Thursday.inner(),  5);
assert_eq!(Weekday::Friday.inner(),    6);
assert_eq!(Weekday::Saturday.inner(),  7);
Source

pub const fn new_saturating(weekday: u8) -> Self

assert_eq!(Weekday::new_saturating(1), Weekday::Sunday);
assert_eq!(Weekday::new_saturating(2), Weekday::Monday);
assert_eq!(Weekday::new_saturating(3), Weekday::Tuesday);
assert_eq!(Weekday::new_saturating(4), Weekday::Wednesday);
assert_eq!(Weekday::new_saturating(5), Weekday::Thursday);
assert_eq!(Weekday::new_saturating(6), Weekday::Friday);
assert_eq!(Weekday::new_saturating(7), Weekday::Saturday);
assert_eq!(Weekday::new_saturating(0), Weekday::Sunday);
assert_eq!(Weekday::new_saturating(7), Weekday::Saturday);
assert_eq!(Weekday::new_saturating(8), Weekday::Saturday);
assert_eq!(Weekday::new_saturating(9), Weekday::Saturday);
Source

pub const fn new_wrapping(weekday: u8) -> Self

// Wraps to Saturday.
assert_eq!(Weekday::new_wrapping(0), Weekday::Saturday);

assert_eq!(Weekday::new_wrapping(1), Weekday::Sunday);
assert_eq!(Weekday::new_wrapping(2), Weekday::Monday);
assert_eq!(Weekday::new_wrapping(3), Weekday::Tuesday);
assert_eq!(Weekday::new_wrapping(4), Weekday::Wednesday);
assert_eq!(Weekday::new_wrapping(5), Weekday::Thursday);
assert_eq!(Weekday::new_wrapping(6), Weekday::Friday);
assert_eq!(Weekday::new_wrapping(7), Weekday::Saturday);

// Wraps to Sunday, Monday, etc
assert_eq!(Weekday::new_wrapping(8),  Weekday::Sunday);
assert_eq!(Weekday::new_wrapping(9),  Weekday::Monday);
assert_eq!(Weekday::new_wrapping(10), Weekday::Tuesday);
assert_eq!(Weekday::new_wrapping(11), Weekday::Wednesday);
assert_eq!(Weekday::new_wrapping(12), Weekday::Thursday);
assert_eq!(Weekday::new_wrapping(13), Weekday::Friday);
assert_eq!(Weekday::new_wrapping(14), Weekday::Saturday);
Source

pub const fn as_u8(self) -> u8

Turn Self into its u8 representation

Source

pub const fn next_saturating(self) -> Self

Get the next Self, saturating if we’re at Self::LAST

Source

pub const fn next_wrapping(self) -> Self

Get the next Self, wrapping if we’re at Self::LAST

Source

pub const fn previous_saturating(self) -> Self

Get the previous Self, saturating if we’re at Self::FIRST

Source

pub const fn previous_wrapping(self) -> Self

Get the previous Self, wrapping if we’re at Self::FIRST

Source

pub const fn add_saturating(self, rhs: u8) -> Self

Add onto Self, saturating if we’re at Self::LAST

Source

pub const fn sub_saturating(self, rhs: u8) -> Self

Subtract from Self, saturating if we’re at Self::FIRST

Source

pub const fn add_wrapping(self, rhs: u8) -> Self

Add onto Self, wrapping if we’re at Self::LAST

Source

pub const fn sub_wrapping(self, rhs: u8) -> Self

Subtract from Self, wrapping if we’re at Self::FIRST

Source

pub const fn as_str(self) -> &'static str

assert_eq!(Weekday::Sunday.as_str(),    "Sunday");
assert_eq!(Weekday::Monday.as_str(),    "Monday");
assert_eq!(Weekday::Tuesday.as_str(),   "Tuesday");
assert_eq!(Weekday::Wednesday.as_str(), "Wednesday");
assert_eq!(Weekday::Thursday.as_str(),  "Thursday");
assert_eq!(Weekday::Friday.as_str(),    "Friday");
assert_eq!(Weekday::Saturday.as_str(),  "Saturday");
Source

pub const fn as_str_lower(self) -> &'static str

assert_eq!(Weekday::Sunday.as_str_lower(),    "sunday");
assert_eq!(Weekday::Monday.as_str_lower(),    "monday");
assert_eq!(Weekday::Tuesday.as_str_lower(),   "tuesday");
assert_eq!(Weekday::Wednesday.as_str_lower(), "wednesday");
assert_eq!(Weekday::Thursday.as_str_lower(),  "thursday");
assert_eq!(Weekday::Friday.as_str_lower(),    "friday");
assert_eq!(Weekday::Saturday.as_str_lower(),  "saturday");
Source

pub const fn as_str_upper(self) -> &'static str

assert_eq!(Weekday::Sunday.as_str_upper(),    "SUNDAY");
assert_eq!(Weekday::Monday.as_str_upper(),    "MONDAY");
assert_eq!(Weekday::Tuesday.as_str_upper(),   "TUESDAY");
assert_eq!(Weekday::Wednesday.as_str_upper(), "WEDNESDAY");
assert_eq!(Weekday::Thursday.as_str_upper(),  "THURSDAY");
assert_eq!(Weekday::Friday.as_str_upper(),    "FRIDAY");
assert_eq!(Weekday::Saturday.as_str_upper(),  "SATURDAY");
Source

pub const fn as_str_short(self) -> &'static str

assert_eq!(Weekday::Sunday.as_str_short(),    "Sun");
assert_eq!(Weekday::Monday.as_str_short(),    "Mon");
assert_eq!(Weekday::Tuesday.as_str_short(),   "Tue");
assert_eq!(Weekday::Wednesday.as_str_short(), "Wed");
assert_eq!(Weekday::Thursday.as_str_short(),  "Thu");
assert_eq!(Weekday::Friday.as_str_short(),    "Fri");
assert_eq!(Weekday::Saturday.as_str_short(),  "Sat");
Source

pub const fn as_str_short_lower(self) -> &'static str

assert_eq!(Weekday::Sunday.as_str_short_lower(),    "sun");
assert_eq!(Weekday::Monday.as_str_short_lower(),    "mon");
assert_eq!(Weekday::Tuesday.as_str_short_lower(),   "tue");
assert_eq!(Weekday::Wednesday.as_str_short_lower(), "wed");
assert_eq!(Weekday::Thursday.as_str_short_lower(),  "thu");
assert_eq!(Weekday::Friday.as_str_short_lower(),    "fri");
assert_eq!(Weekday::Saturday.as_str_short_lower(),  "sat");
Source

pub const fn as_str_short_upper(self) -> &'static str

assert_eq!(Weekday::Sunday.as_str_short_upper(),    "SUN");
assert_eq!(Weekday::Monday.as_str_short_upper(),    "MON");
assert_eq!(Weekday::Tuesday.as_str_short_upper(),   "TUE");
assert_eq!(Weekday::Wednesday.as_str_short_upper(), "WED");
assert_eq!(Weekday::Thursday.as_str_short_upper(),  "THU");
assert_eq!(Weekday::Friday.as_str_short_upper(),    "FRI");
assert_eq!(Weekday::Saturday.as_str_short_upper(),  "SAT");
Source

pub const fn as_str_jp(self) -> &'static str

assert_eq!(Weekday::Sunday.as_str_jp(),    "日曜日");
assert_eq!(Weekday::Monday.as_str_jp(),    "月曜日");
assert_eq!(Weekday::Tuesday.as_str_jp(),   "火曜日");
assert_eq!(Weekday::Wednesday.as_str_jp(), "水曜日");
assert_eq!(Weekday::Thursday.as_str_jp(),  "木曜日");
assert_eq!(Weekday::Friday.as_str_jp(),    "金曜日");
assert_eq!(Weekday::Saturday.as_str_jp(),  "土曜日");
Source

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

Create a Weekday by parsing a &str

A valid input string can either be the first 3 letters of the day (returned from Weekday::as_str_short) or the full weekday (returned from Weekday::as_str).

These cases are covered:

  • lowercase
  • UPPERCASE

For example:

assert_eq!(Weekday::from_str("SUN").unwrap(),    Weekday::Sunday);
assert_eq!(Weekday::from_str("Sun").unwrap(),    Weekday::Sunday);
assert_eq!(Weekday::from_str("sun").unwrap(),    Weekday::Sunday);
assert_eq!(Weekday::from_str("SUNDAY").unwrap(), Weekday::Sunday);
assert_eq!(Weekday::from_str("Sunday").unwrap(), Weekday::Sunday);
assert_eq!(Weekday::from_str("sunday").unwrap(), Weekday::Sunday);

If:

  • s.len() < 3
  • s.len() > 9
  • The string could not be parsed then this function will return None.
§Parsing Exceptions

Weekday::Tuesday can be parsed from

  • tue
  • tues

Weekday::Thursday can be parsed from:

  • thu
  • thur
  • thurs

(and all case-combinations).

§Examples
assert_eq!(Weekday::from_str("SUN").unwrap(),    Weekday::Sunday);
assert_eq!(Weekday::from_str("Sun").unwrap(),    Weekday::Sunday);
assert_eq!(Weekday::from_str("sun").unwrap(),    Weekday::Sunday);
assert_eq!(Weekday::from_str("SUNDAY").unwrap(), Weekday::Sunday);
assert_eq!(Weekday::from_str("Sunday").unwrap(), Weekday::Sunday);
assert_eq!(Weekday::from_str("sunday").unwrap(), Weekday::Sunday);

assert_eq!(Weekday::from_str("MON").unwrap(),    Weekday::Monday);
assert_eq!(Weekday::from_str("Mon").unwrap(),    Weekday::Monday);
assert_eq!(Weekday::from_str("mon").unwrap(),    Weekday::Monday);
assert_eq!(Weekday::from_str("MONDAY").unwrap(), Weekday::Monday);
assert_eq!(Weekday::from_str("Monday").unwrap(), Weekday::Monday);
assert_eq!(Weekday::from_str("monday").unwrap(), Weekday::Monday);

assert_eq!(Weekday::from_str("TUES").unwrap(),    Weekday::Tuesday);
assert_eq!(Weekday::from_str("Tues").unwrap(),    Weekday::Tuesday);
assert_eq!(Weekday::from_str("tues").unwrap(),    Weekday::Tuesday);
assert_eq!(Weekday::from_str("TUE").unwrap(),     Weekday::Tuesday);
assert_eq!(Weekday::from_str("Tue").unwrap(),     Weekday::Tuesday);
assert_eq!(Weekday::from_str("tue").unwrap(),     Weekday::Tuesday);
assert_eq!(Weekday::from_str("TUESDAY").unwrap(), Weekday::Tuesday);
assert_eq!(Weekday::from_str("Tuesday").unwrap(), Weekday::Tuesday);
assert_eq!(Weekday::from_str("tuesday").unwrap(), Weekday::Tuesday);

assert_eq!(Weekday::from_str("WED").unwrap(),       Weekday::Wednesday);
assert_eq!(Weekday::from_str("Wed").unwrap(),       Weekday::Wednesday);
assert_eq!(Weekday::from_str("wed").unwrap(),       Weekday::Wednesday);
assert_eq!(Weekday::from_str("WEDNESDAY").unwrap(), Weekday::Wednesday);
assert_eq!(Weekday::from_str("Wednesday").unwrap(), Weekday::Wednesday);
assert_eq!(Weekday::from_str("wednesday").unwrap(), Weekday::Wednesday);

assert_eq!(Weekday::from_str("THURS").unwrap(),    Weekday::Thursday);
assert_eq!(Weekday::from_str("Thurs").unwrap(),    Weekday::Thursday);
assert_eq!(Weekday::from_str("thurs").unwrap(),    Weekday::Thursday);
assert_eq!(Weekday::from_str("THUR").unwrap(),     Weekday::Thursday);
assert_eq!(Weekday::from_str("Thur").unwrap(),     Weekday::Thursday);
assert_eq!(Weekday::from_str("thur").unwrap(),     Weekday::Thursday);
assert_eq!(Weekday::from_str("THURSDAY").unwrap(), Weekday::Thursday);
assert_eq!(Weekday::from_str("Thursday").unwrap(), Weekday::Thursday);
assert_eq!(Weekday::from_str("thursday").unwrap(), Weekday::Thursday);

assert_eq!(Weekday::from_str("FRI").unwrap(),    Weekday::Friday);
assert_eq!(Weekday::from_str("Fri").unwrap(),    Weekday::Friday);
assert_eq!(Weekday::from_str("fri").unwrap(),    Weekday::Friday);
assert_eq!(Weekday::from_str("FRIDAY").unwrap(), Weekday::Friday);
assert_eq!(Weekday::from_str("Friday").unwrap(), Weekday::Friday);
assert_eq!(Weekday::from_str("friday").unwrap(), Weekday::Friday);

assert_eq!(Weekday::from_str("SAT").unwrap(),      Weekday::Saturday);
assert_eq!(Weekday::from_str("Sat").unwrap(),      Weekday::Saturday);
assert_eq!(Weekday::from_str("sat").unwrap(),      Weekday::Saturday);
assert_eq!(Weekday::from_str("SATURDAY").unwrap(), Weekday::Saturday);
assert_eq!(Weekday::from_str("Saturday").unwrap(), Weekday::Saturday);
assert_eq!(Weekday::from_str("saturday").unwrap(), Weekday::Saturday);
Source

pub const fn from_bytes(bytes: &[u8]) -> Option<Self>

Same as Self::from_str but with bytes

§Safety

bytes must be valid UTF-8.

Trait Implementations§

Source§

impl<'__de, __Context> BorrowDecode<'__de, __Context> for Weekday

Source§

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

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

impl Clone for Weekday

Source§

fn clone(&self) -> Weekday

Returns a duplicate 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 Weekday

Source§

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

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

impl<__Context> Decode<__Context> for Weekday

Source§

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

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

impl Default for Weekday

Source§

fn default() -> Weekday

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

impl<'de> Deserialize<'de> for Weekday

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 Encode for Weekday

Source§

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

Encode a given type.
Source§

impl From<&i128> for Weekday

Source§

fn from(value: &i128) -> Self

Source§

impl From<&i16> for Weekday

Source§

fn from(value: &i16) -> Self

Source§

impl From<&i32> for Weekday

Source§

fn from(value: &i32) -> Self

Source§

impl From<&i64> for Weekday

Source§

fn from(value: &i64) -> Self

Source§

impl From<&i8> for Weekday

Source§

fn from(value: &i8) -> Self

Source§

impl From<&isize> for Weekday

Source§

fn from(value: &isize) -> Self

Source§

impl From<&u128> for Weekday

Source§

fn from(value: &u128) -> Self

Source§

impl From<&u16> for Weekday

Source§

fn from(value: &u16) -> Self

Source§

impl From<&u32> for Weekday

Source§

fn from(value: &u32) -> Self

Source§

impl From<&u64> for Weekday

Source§

fn from(value: &u64) -> Self

Source§

impl From<&u8> for Weekday

Source§

fn from(value: &u8) -> Self

Source§

impl From<&usize> for Weekday

Source§

fn from(value: &usize) -> Self

Source§

impl From<i128> for Weekday

Source§

fn from(value: i128) -> Self

Source§

impl From<i16> for Weekday

Source§

fn from(value: i16) -> Self

Source§

impl From<i32> for Weekday

Source§

fn from(value: i32) -> Self

Source§

impl From<i64> for Weekday

Source§

fn from(value: i64) -> Self

Source§

impl From<i8> for Weekday

Source§

fn from(value: i8) -> Self

Source§

impl From<isize> for Weekday

Source§

fn from(value: isize) -> Self

Source§

impl From<u128> for Weekday

Source§

fn from(value: u128) -> Self

Source§

impl From<u16> for Weekday

Source§

fn from(value: u16) -> Self

Source§

impl From<u32> for Weekday

Source§

fn from(value: u32) -> Self

Source§

impl From<u64> for Weekday

Source§

fn from(value: u64) -> Self

Source§

impl From<u8> for Weekday

Source§

fn from(value: u8) -> Self

Source§

impl From<usize> for Weekday

Source§

fn from(value: usize) -> Self

Source§

impl Hash for Weekday

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 Ord for Weekday

Source§

fn cmp(&self, other: &Weekday) -> 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,

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

impl PartialEq for Weekday

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Weekday

Source§

fn partial_cmp(&self, other: &Weekday) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Weekday

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 Copy for Weekday

Source§

impl Eq for Weekday

Source§

impl StructuralPartialEq for Weekday

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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>,