version_check

Struct Date

Source
pub struct Date(/* private fields */);
Expand description

Release date including year, month, and day.

Implementations§

Source§

impl Date

Source

pub fn read() -> Option<Date>

Reads the release date of the running compiler. If it cannot be determined (see the top-level documentation), returns None.

§Example
use version_check::Date;

match Date::read() {
    Some(d) => format!("The release date is: {}", d),
    None => format!("Failed to read the release date.")
};
Source

pub fn parse(date: &str) -> Option<Date>

Parse a release date of the form %Y-%m-%d. Returns None if date is not in %Y-%m-%d format.

§Example
use version_check::Date;

let date = Date::parse("2016-04-20").unwrap();

assert!(date.at_least("2016-01-10"));
assert!(date.at_most("2016-04-20"));
assert!(date.exactly("2016-04-20"));

assert!(Date::parse("2021-12-31").unwrap().exactly("2021-12-31"));

assert!(Date::parse("March 13, 2018").is_none());
assert!(Date::parse("1-2-3-4-5").is_none());
assert!(Date::parse("2020-300-23120").is_none());
assert!(Date::parse("2020-12-12 1").is_none());
assert!(Date::parse("2020-10").is_none());
assert!(Date::parse("2020").is_none());
Source

pub fn from_ymd(year: u16, month: u8, day: u8) -> Date

Creates a Date from (year, month, day) date components.

Does not check the validity of year, month, or day, but year is truncated to 23 bits (% 8,388,608), month to 4 bits (% 16), and day to 5 bits (% 32).

§Example
use version_check::Date;

assert!(Date::from_ymd(2021, 7, 30).exactly("2021-07-30"));
assert!(Date::from_ymd(2010, 3, 23).exactly("2010-03-23"));
assert!(Date::from_ymd(2090, 1, 31).exactly("2090-01-31"));

// Truncation: 33 % 32 == 0x21 & 0x1F == 1.
assert!(Date::from_ymd(2090, 1, 33).exactly("2090-01-01"));
Source

pub fn at_least(&self, date: &str) -> bool

Returns true if self occurs on or after date.

If date occurs before self, or if date is not in %Y-%m-%d format, returns false.

§Example
use version_check::Date;

let date = Date::parse("2020-01-01").unwrap();

assert!(date.at_least("2019-12-31"));
assert!(date.at_least("2020-01-01"));
assert!(date.at_least("2014-04-31"));

assert!(!date.at_least("2020-01-02"));
assert!(!date.at_least("2024-08-18"));
Source

pub fn at_most(&self, date: &str) -> bool

Returns true if self occurs on or before date.

If date occurs after self, or if date is not in %Y-%m-%d format, returns false.

§Example
use version_check::Date;

let date = Date::parse("2020-01-01").unwrap();

assert!(date.at_most("2020-01-01"));
assert!(date.at_most("2020-01-02"));
assert!(date.at_most("2024-08-18"));

assert!(!date.at_most("2019-12-31"));
assert!(!date.at_most("2014-04-31"));
Source

pub fn exactly(&self, date: &str) -> bool

Returns true if self occurs exactly on date.

If date is not exactly self, or if date is not in %Y-%m-%d format, returns false.

§Example
use version_check::Date;

let date = Date::parse("2020-01-01").unwrap();

assert!(date.exactly("2020-01-01"));

assert!(!date.exactly("2019-12-31"));
assert!(!date.exactly("2014-04-31"));
assert!(!date.exactly("2020-01-02"));
assert!(!date.exactly("2024-08-18"));

Trait Implementations§

Source§

impl Clone for Date

Source§

fn clone(&self) -> Date

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 Date

Source§

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

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

impl Display for Date

Source§

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

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

impl Ord for Date

Source§

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

Source§

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

Source§

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

Source§

impl Eq for Date

Source§

impl StructuralPartialEq for Date

Auto Trait Implementations§

§

impl Freeze for Date

§

impl RefUnwindSafe for Date

§

impl Send for Date

§

impl Sync for Date

§

impl Unpin for Date

§

impl UnwindSafe for Date

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToString for T
where T: Display + ?Sized,

Source§

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

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.