Struct TimeUnit

Source
pub struct TimeUnit { /* private fields */ }
Available on crate feature time only.
Expand description

Unit of time

Unlike most readable types, this struct is not a string; it is a utility type that takes seconds as input and calculates the different units of time from it.

For example:

assert_eq!(TimeUnit::from(1).seconds(), 1);
assert_eq!(TimeUnit::from(60).minutes(), 1);
assert_eq!(TimeUnit::from(3600).hours(), 1);
assert_eq!(TimeUnit::from(86400).days(), 1);
assert_eq!(TimeUnit::from(86400 * 7).weeks(), 1);
assert_eq!(TimeUnit::from(86400 * 31).months(), 1);
assert_eq!(TimeUnit::from(86400 * 365).years(), 1);

If a unit overflows it will carry over to the lower unit, for example:

let unit = TimeUnit::from(
    31536000 + // 1 year
    5356800  + // 2 months
    1814400  + // 3 weeks
    345600   + // 4 days
    18000    + // 5 hours
    360      + // 6 minutes
    7          // 7 seconds
);

assert_eq!(unit.years(),   1);
assert_eq!(unit.months(),  2);
assert_eq!(unit.weeks(),   3);
assert_eq!(unit.days(),    4);
assert_eq!(unit.hours(),   5);
assert_eq!(unit.minutes(), 6);
assert_eq!(unit.seconds(), 7);

// Total amount of seconds.
assert_eq!(unit.inner(), 39071167);

§Size

assert_eq!(std::mem::size_of::<TimeUnit>(), 12);

§Uptime & Conversion

Like the other readable::time types, TimeUnit implements Uptime and can be losslessly convert from/into other readable::time types, even maintaining unknown variants:

// Uptime
let time = Uptime::from(86461);
assert_eq!(time, "1d, 1m, 1s");

// TimeUnit
let unit = TimeUnit::from(time);
assert_eq!(unit.inner(),   86461);
assert_eq!(unit.years(),   0);
assert_eq!(unit.months(),  0);
assert_eq!(unit.weeks(),   0);
assert_eq!(unit.days(),    1);
assert_eq!(unit.hours(),   0);
assert_eq!(unit.minutes(), 1);
assert_eq!(unit.seconds(), 1);

// Maintain the `unknown` variant.
let time: Uptime   = Uptime::UNKNOWN;
let unit: TimeUnit = TimeUnit::from(time);
assert!(unit.is_unknown());
let time: Uptime = Uptime::from(unit);
assert!(time.is_unknown());

§Naive time

Like the othear readable::time types, TimeUnit naively assumes that:

  1. Each day is 86400 seconds
  2. Each month is 31 days
  3. Each year is 365 days

This is incorrect as not all months are 31 days long and leap years exist.

Implementations§

Source§

impl TimeUnit

Source

pub const UNKNOWN: Self

assert_eq!(TimeUnit::UNKNOWN.inner(),   0);
assert_eq!(TimeUnit::UNKNOWN.years(),   0);
assert_eq!(TimeUnit::UNKNOWN.months(),  0);
assert_eq!(TimeUnit::UNKNOWN.weeks(),   0);
assert_eq!(TimeUnit::UNKNOWN.days(),    0);
assert_eq!(TimeUnit::UNKNOWN.hours(),   0);
assert_eq!(TimeUnit::UNKNOWN.minutes(), 0);
assert_eq!(TimeUnit::UNKNOWN.seconds(), 0);
assert_eq!(TimeUnit::UNKNOWN, TimeUnit::from(-1));
assert_eq!(TimeUnit::UNKNOWN, TimeUnit::from(u64::MAX));
assert_eq!(TimeUnit::UNKNOWN, TimeUnit::from(f32::NAN));
assert!(TimeUnit::UNKNOWN.is_unknown());
Source

pub const ZERO: Self

assert_eq!(TimeUnit::ZERO.inner(), 0);
assert_eq!(TimeUnit::ZERO, TimeUnit::from(0));
Source

pub const SECOND: Self

assert_eq!(TimeUnit::SECOND.inner(), 1);
assert_eq!(TimeUnit::SECOND.seconds(), 1);
assert_eq!(TimeUnit::SECOND, TimeUnit::from(1));
Source

pub const MINUTE: Self

assert_eq!(TimeUnit::MINUTE.inner(), 60);
assert_eq!(TimeUnit::MINUTE.minutes(), 1);
assert_eq!(TimeUnit::MINUTE, TimeUnit::from(60));
Source

pub const HOUR: Self

assert_eq!(TimeUnit::HOUR.inner(), 3600);
assert_eq!(TimeUnit::HOUR.hours(), 1);
assert_eq!(TimeUnit::HOUR, TimeUnit::from(3600));
Source

pub const DAY: Self

assert_eq!(TimeUnit::DAY.inner(), 86400);
assert_eq!(TimeUnit::DAY.days(), 1);
assert_eq!(TimeUnit::DAY, TimeUnit::from(86400));
Source

pub const WEEK: Self

assert_eq!(TimeUnit::WEEK.inner(), 604800);
assert_eq!(TimeUnit::WEEK.weeks(), 1);
assert_eq!(TimeUnit::WEEK, TimeUnit::from(604800));
Source

pub const MONTH: Self

assert_eq!(TimeUnit::MONTH.inner(), 2678400);
assert_eq!(TimeUnit::MONTH.months(), 1);
assert_eq!(TimeUnit::MONTH, TimeUnit::from(2678400));
Source

pub const YEAR: Self

assert_eq!(TimeUnit::YEAR.inner(), 31536000);
assert_eq!(TimeUnit::YEAR.years(), 1);
assert_eq!(TimeUnit::YEAR, TimeUnit::from(31536000));
Source

pub const MAX: Self

assert_eq!(TimeUnit::MAX.inner(),   u32::MAX);
assert_eq!(TimeUnit::MAX.years(),   136);
assert_eq!(TimeUnit::MAX.months(),  2);
assert_eq!(TimeUnit::MAX.weeks(),   1);
assert_eq!(TimeUnit::MAX.days(),    1);
assert_eq!(TimeUnit::MAX.hours(),   6);
assert_eq!(TimeUnit::MAX.minutes(), 28);
assert_eq!(TimeUnit::MAX.seconds(), 15);
assert_eq!(TimeUnit::MAX, TimeUnit::from(u32::MAX));
Source§

impl TimeUnit

Source

pub const fn new(secs: u32) -> Self

Create a new TimeUnit from seconds as input.

This will divide and use the remainder to calculate each unit, for example 62 as input would lead to 1 minute and 2 seconds.

let unit = TimeUnit::from(62);
assert_eq!(unit.minutes(), 1);
assert_eq!(unit.seconds(), 2);
Source

pub const fn from_minutes(minutes: u32) -> Self

Create Self with minutes as input

let unit = TimeUnit::from_minutes(1);
assert_eq!(unit.inner(), 60);
§Maximum Input

The maximum input is 71_582_788 minutes before this function saturates.

Source

pub const fn from_hours(hours: u32) -> Self

Create Self with hours as input

let unit = TimeUnit::from_hours(1);
assert_eq!(unit.inner(), 3_600);
§Maximum Input

The maximum input is 1_193_046 hours before this function saturates.

Source

pub const fn from_days(days: u16) -> Self

Create Self with days as input

let unit = TimeUnit::from_days(1);
assert_eq!(unit.inner(), 86_400);
§Maximum Input

The maximum input is 49_710 days before this function saturates.

Source

pub const fn from_weeks(weeks: u16) -> Self

Create Self with weeks as input

let unit = TimeUnit::from_weeks(1);
assert_eq!(unit.inner(), 604_800);
§Maximum Input

The maximum input is 7_101 weeks before this function saturates.

Source

pub const fn from_months(months: u16) -> Self

Create Self with months as input

let unit = TimeUnit::from_months(1);
assert_eq!(unit.inner(), 2_678_400);
§Maximum Input

The maximum input is 1_603 months before this function saturates.

Source

pub const fn from_years(years: u8) -> Self

Create Self with years as input

let unit = TimeUnit::from_years(1);
assert_eq!(unit.inner(), 31_536_000);
§Maximum Input

The maximum input is 136 years before this function saturates.

Source

pub const fn new_variety( years: u8, months: u16, weeks: u16, days: u16, hours: u32, minutes: u32, seconds: u32, ) -> Self

Create a new TimeUnit from a variety of input

This multiplies and combines all the input.

§Maximum Input

If the total second count of all the inputs combined exceeds u32::MAX then this function will saturate and return TimeUnit::MAX.

§Examples
let unit = TimeUnit::new_variety(
    0, // years   (0s)
    1, // months  (2678400s)
    2, // weeks   (1209600s)
    3, // days    (259200s)
    4, // hours   (14400s)
    5, // minutes (300s)
    6, // seconds (6s)
);

// Total second count: 4,161,906 seconds
assert_eq!(unit.inner(), 4_161_906);
assert_eq!(unit.years(),   0);
assert_eq!(unit.months(),  1);
assert_eq!(unit.weeks(),   2);
assert_eq!(unit.days(),    3);
assert_eq!(unit.hours(),   4);
assert_eq!(unit.minutes(), 5);
assert_eq!(unit.seconds(), 6);

Example of saturating inputs.

let unit = TimeUnit::new_variety(
    172,   // years
    134,   // months
    22,    // weeks
    32575, // days
    46,    // hours
    5123,  // minutes
    54,    // seconds
);

assert_eq!(unit, TimeUnit::MAX);
Source

pub const fn into_raw(self) -> (bool, u32, u8, u8, u8, u8, u8, u8, u8)

Returns the internal structure.

A tuple is returned mirroring the internal structure of TimeUnit, going from left-to-right:

§Example
let (
    unknown,
    inner,
    years,
    months,
    weeks,
    days,
    hours,
    minutes,
    seconds,
) = TimeUnit::from(39071167).into_raw();

assert_eq!(unknown, false);
assert_eq!(inner,   39071167);
assert_eq!(years,   1);
assert_eq!(months,  2);
assert_eq!(weeks,   3);
assert_eq!(days,    4);
assert_eq!(hours,   5);
assert_eq!(minutes, 6);
assert_eq!(seconds, 7);
Source

pub const fn to_raw(&self) -> (bool, u32, u8, u8, u8, u8, u8, u8, u8)

Same as TimeUnit::into_raw() but does not destruct self

Source

pub const fn is_unknown(&self) -> bool

An unknown TimeUnit can be created on irregular input (negative integer, NaN float, etc) or if it was converted from a different readable::time type that was unknown.

This function checks if self is unknown.

Although all inner numbers are all set to 0, a flag is set internally such that:

assert!(TimeUnit::ZERO != TimeUnit::UNKNOWN);
§Examples
assert!(TimeUnit::UNKNOWN.is_unknown());
assert!(TimeUnit::from(Uptime::UNKNOWN).is_unknown());
assert!(TimeUnit::from(f32::NAN).is_unknown());
assert!(TimeUnit::from(-1).is_unknown());
Source

pub const fn inner(&self) -> u32

Returns the total amount of seconds this TimeUnit represents.

let unit = TimeUnit::from(123);

assert_eq!(unit.minutes(), 2);
assert_eq!(unit.seconds(), 3);
assert_eq!(unit.inner(), 123);
Source

pub const fn years(&self) -> u8

Returns the remaining amount of years this TimeUnit represents.

assert_eq!(TimeUnit::from(86400 * 364).years(), 0);
assert_eq!(TimeUnit::from(86400 * 365).years(), 1);
Source

pub const fn months(&self) -> u8

Returns the remaining amount of months this TimeUnit represents.

assert_eq!(TimeUnit::from(86400 * 30).months(), 0);
assert_eq!(TimeUnit::from(86400 * 31).months(), 1);
Source

pub const fn weeks(&self) -> u8

Returns the remaining amount of weeks this TimeUnit represents.

assert_eq!(TimeUnit::from(86400 * 6).weeks(), 0);
assert_eq!(TimeUnit::from(86400 * 7).weeks(), 1);
Source

pub const fn days(&self) -> u8

Returns the remaining amount of days this TimeUnit represents.

assert_eq!(TimeUnit::from(86399).days(), 0);
assert_eq!(TimeUnit::from(86400).days(), 1);
Source

pub const fn hours(&self) -> u8

Returns the remaining amount of hours this TimeUnit represents.

assert_eq!(TimeUnit::from(3599).hours(), 0);
assert_eq!(TimeUnit::from(3600).hours(), 1);
Source

pub const fn minutes(&self) -> u8

Returns the remaining amount of minutes this TimeUnit represents.

assert_eq!(TimeUnit::from(59).minutes(), 0);
assert_eq!(TimeUnit::from(60).minutes(), 1);
Source

pub const fn seconds(&self) -> u8

Returns the remaining amount of seconds this TimeUnit represents.

This is the remaining amount of seconds, not the total amount of seconds.

// `0` is returned since `60` is == `1 minute`.
assert_eq!(TimeUnit::from(60).seconds(), 0);
assert_eq!(TimeUnit::from(60).minutes(), 1);
assert_eq!(TimeUnit::from(60).inner(), 60);

// `1` is returned since there's 1 remaining second.
assert_eq!(TimeUnit::from(61).seconds(), 1);
assert_eq!(TimeUnit::from(61).minutes(), 1);
assert_eq!(TimeUnit::from(61).inner(),   61);

Trait Implementations§

Source§

impl Add<&TimeUnit> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the + operator.
Source§

fn add(self, other: &TimeUnit) -> Self

Performs the + operation. Read more
Source§

impl Add<&TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the + operator.
Source§

fn add(self, other: &TimeUnit) -> Self

Performs the + operation. Read more
Source§

impl Add<&u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the + operator.
Source§

fn add(self, other: &u32) -> Self

Performs the + operation. Read more
Source§

impl Add<TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the + operator.
Source§

fn add(self, other: TimeUnit) -> Self

Performs the + operation. Read more
Source§

impl Add<u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the + operator.
Source§

fn add(self, other: u32) -> Self

Performs the + operation. Read more
Source§

impl Add for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the + operator.
Source§

fn add(self, other: TimeUnit) -> Self

Performs the + operation. Read more
Source§

impl<'__de> BorrowDecode<'__de> for TimeUnit

Source§

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

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

impl BorshDeserialize for TimeUnit

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for TimeUnit

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl Clone for TimeUnit

Source§

fn clone(&self) -> TimeUnit

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 TimeUnit

Source§

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

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

impl Decode for TimeUnit

Source§

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

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

impl Default for TimeUnit

Source§

fn default() -> Self

Calls Self::ZERO

Source§

impl<'de> Deserialize<'de> for TimeUnit

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 Div<&TimeUnit> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the / operator.
Source§

fn div(self, other: &TimeUnit) -> Self

Performs the / operation. Read more
Source§

impl Div<&TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the / operator.
Source§

fn div(self, other: &TimeUnit) -> Self

Performs the / operation. Read more
Source§

impl Div<&u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the / operator.
Source§

fn div(self, other: &u32) -> Self

Performs the / operation. Read more
Source§

impl Div<TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the / operator.
Source§

fn div(self, other: TimeUnit) -> Self

Performs the / operation. Read more
Source§

impl Div<u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the / operator.
Source§

fn div(self, other: u32) -> Self

Performs the / operation. Read more
Source§

impl Div for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the / operator.
Source§

fn div(self, other: TimeUnit) -> Self

Performs the / operation. Read more
Source§

impl Encode for TimeUnit

Source§

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

Encode a given type.
Source§

impl From<&Duration> for TimeUnit

Source§

fn from(duration: &Duration) -> Self

Converts to this type from the input type.
Source§

impl From<&Htop> for TimeUnit

Source§

fn from(from: &Htop) -> Self

Converts to this type from the input type.
Source§

impl From<&Instant> for TimeUnit

Source§

fn from(instant: &Instant) -> Self

Converts to this type from the input type.
Source§

impl From<&Military> for TimeUnit

Source§

fn from(from: &Military) -> Self

Converts to this type from the input type.
Source§

impl From<&Time> for TimeUnit

Source§

fn from(from: &Time) -> Self

Converts to this type from the input type.
Source§

impl From<&TimeUnit> for Duration

Source§

fn from(value: &TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<&TimeUnit> for Htop

Available on crate feature up only.
Source§

fn from(from: &TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<&TimeUnit> for Military

Source§

fn from(other: &TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<&TimeUnit> for Time

Source§

fn from(other: &TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<&TimeUnit> for Uptime

Available on crate feature up only.
Source§

fn from(from: &TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<&TimeUnit> for UptimeFull

Available on crate feature up only.
Source§

fn from(from: &TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<&Unsigned> for TimeUnit

Source§

fn from(from: &Unsigned) -> Self

Converts to this type from the input type.
Source§

impl From<&Uptime> for TimeUnit

Source§

fn from(from: &Uptime) -> Self

Converts to this type from the input type.
Source§

impl From<&UptimeFull> for TimeUnit

Source§

fn from(from: &UptimeFull) -> Self

Converts to this type from the input type.
Source§

impl From<&f32> for TimeUnit

Source§

fn from(float: &f32) -> Self

Converts to this type from the input type.
Source§

impl From<&f64> for TimeUnit

Source§

fn from(float: &f64) -> Self

Converts to this type from the input type.
Source§

impl From<&i128> for TimeUnit

Source§

fn from(int: &i128) -> Self

Converts to this type from the input type.
Source§

impl From<&i16> for TimeUnit

Source§

fn from(int: &i16) -> Self

Converts to this type from the input type.
Source§

impl From<&i32> for TimeUnit

Source§

fn from(int: &i32) -> Self

Converts to this type from the input type.
Source§

impl From<&i64> for TimeUnit

Source§

fn from(int: &i64) -> Self

Converts to this type from the input type.
Source§

impl From<&i8> for TimeUnit

Source§

fn from(int: &i8) -> Self

Converts to this type from the input type.
Source§

impl From<&isize> for TimeUnit

Source§

fn from(u: &isize) -> Self

Converts to this type from the input type.
Source§

impl From<&u128> for TimeUnit

Source§

fn from(u: &u128) -> Self

Converts to this type from the input type.
Source§

impl From<&u16> for TimeUnit

Source§

fn from(u: &u16) -> Self

Converts to this type from the input type.
Source§

impl From<&u32> for TimeUnit

Source§

fn from(u: &u32) -> Self

Converts to this type from the input type.
Source§

impl From<&u64> for TimeUnit

Source§

fn from(u: &u64) -> Self

Converts to this type from the input type.
Source§

impl From<&u8> for TimeUnit

Source§

fn from(u: &u8) -> Self

Converts to this type from the input type.
Source§

impl From<&usize> for TimeUnit

Source§

fn from(u: &usize) -> Self

Converts to this type from the input type.
Source§

impl From<Duration> for TimeUnit

Source§

fn from(duration: Duration) -> Self

Converts to this type from the input type.
Source§

impl From<Htop> for TimeUnit

Source§

fn from(from: Htop) -> Self

Converts to this type from the input type.
Source§

impl From<Instant> for TimeUnit

Source§

fn from(instant: Instant) -> Self

Converts to this type from the input type.
Source§

impl From<Military> for TimeUnit

Source§

fn from(from: Military) -> Self

Converts to this type from the input type.
Source§

impl From<Time> for TimeUnit

Source§

fn from(from: Time) -> Self

Converts to this type from the input type.
Source§

impl From<TimeUnit> for Duration

Source§

fn from(value: TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<TimeUnit> for Htop

Available on crate feature up only.
Source§

fn from(from: TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<TimeUnit> for Military

Source§

fn from(other: TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<TimeUnit> for Time

Source§

fn from(other: TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<TimeUnit> for Uptime

Available on crate feature up only.
Source§

fn from(from: TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<TimeUnit> for UptimeFull

Available on crate feature up only.
Source§

fn from(from: TimeUnit) -> Self

Converts to this type from the input type.
Source§

impl From<Unsigned> for TimeUnit

Source§

fn from(from: Unsigned) -> Self

Converts to this type from the input type.
Source§

impl From<Uptime> for TimeUnit

Source§

fn from(from: Uptime) -> Self

Converts to this type from the input type.
Source§

impl From<UptimeFull> for TimeUnit

Source§

fn from(from: UptimeFull) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for TimeUnit

Source§

fn from(float: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for TimeUnit

Source§

fn from(float: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for TimeUnit

Source§

fn from(int: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for TimeUnit

Source§

fn from(int: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for TimeUnit

Source§

fn from(int: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for TimeUnit

Source§

fn from(int: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for TimeUnit

Source§

fn from(int: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for TimeUnit

Source§

fn from(u: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for TimeUnit

Source§

fn from(u: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for TimeUnit

Source§

fn from(u: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for TimeUnit

Source§

fn from(u: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for TimeUnit

Source§

fn from(u: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for TimeUnit

Source§

fn from(u: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for TimeUnit

Source§

fn from(u: usize) -> Self

Converts to this type from the input type.
Source§

impl Hash for TimeUnit

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 Mul<&TimeUnit> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the * operator.
Source§

fn mul(self, other: &TimeUnit) -> Self

Performs the * operation. Read more
Source§

impl Mul<&TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the * operator.
Source§

fn mul(self, other: &TimeUnit) -> Self

Performs the * operation. Read more
Source§

impl Mul<&u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the * operator.
Source§

fn mul(self, other: &u32) -> Self

Performs the * operation. Read more
Source§

impl Mul<TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the * operator.
Source§

fn mul(self, other: TimeUnit) -> Self

Performs the * operation. Read more
Source§

impl Mul<u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the * operator.
Source§

fn mul(self, other: u32) -> Self

Performs the * operation. Read more
Source§

impl Mul for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the * operator.
Source§

fn mul(self, other: TimeUnit) -> Self

Performs the * operation. Read more
Source§

impl Ord for TimeUnit

Source§

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

Source§

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

Source§

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

Source§

type Output = TimeUnit

The resulting type after applying the % operator.
Source§

fn rem(self, other: &TimeUnit) -> Self

Performs the % operation. Read more
Source§

impl Rem<&TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the % operator.
Source§

fn rem(self, other: &TimeUnit) -> Self

Performs the % operation. Read more
Source§

impl Rem<&u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the % operator.
Source§

fn rem(self, other: &u32) -> Self

Performs the % operation. Read more
Source§

impl Rem<TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the % operator.
Source§

fn rem(self, other: TimeUnit) -> Self

Performs the % operation. Read more
Source§

impl Rem<u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the % operator.
Source§

fn rem(self, other: u32) -> Self

Performs the % operation. Read more
Source§

impl Rem for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the % operator.
Source§

fn rem(self, other: TimeUnit) -> Self

Performs the % operation. Read more
Source§

impl Serialize for TimeUnit

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 Sub<&TimeUnit> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the - operator.
Source§

fn sub(self, other: &TimeUnit) -> Self

Performs the - operation. Read more
Source§

impl Sub<&TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the - operator.
Source§

fn sub(self, other: &TimeUnit) -> Self

Performs the - operation. Read more
Source§

impl Sub<&u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the - operator.
Source§

fn sub(self, other: &u32) -> Self

Performs the - operation. Read more
Source§

impl Sub<TimeUnit> for u32

Source§

type Output = u32

The resulting type after applying the - operator.
Source§

fn sub(self, other: TimeUnit) -> Self

Performs the - operation. Read more
Source§

impl Sub<u32> for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the - operator.
Source§

fn sub(self, other: u32) -> Self

Performs the - operation. Read more
Source§

impl Sub for TimeUnit

Source§

type Output = TimeUnit

The resulting type after applying the - operator.
Source§

fn sub(self, other: TimeUnit) -> Self

Performs the - operation. Read more
Source§

impl SysTime for TimeUnit

Source§

fn sys_time() -> Self

This function creates a Self from the live system date Read more
Source§

impl SysUptime for TimeUnit

Available on crate feature up only.
Source§

fn sys_uptime() -> Self

This function creates a Self from the live system uptime and can be used on: Read more
Source§

impl Copy for TimeUnit

Source§

impl Eq for TimeUnit

Source§

impl StructuralPartialEq for TimeUnit

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

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<T, Base> RefNum<Base> for T
where T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,