pub struct TimeUnits(/* private fields */);Expand description
Units of time elapsed since the beginning of the current hour.
TimeUnits is guaranteed to be less than 2147483648.
A time unit is approximately 1676.38063431 nanoseconds.
Implementations§
Source§impl TimeUnits
impl TimeUnits
Sourcepub const MAX: Self
pub const MAX: Self
Maximum TimeUnits representing one time unit before the start of the next hour.
Sourcepub const fn new(value: u32) -> Option<Self>
pub const fn new(value: u32) -> Option<Self>
Constructs a new TimeUnits from value if less than 2147483648.
§Examples
let time_units = TimeUnits::new(1_073_741_824);
assert!(matches!(time_units, Some(_)));
assert_eq!(time_units.unwrap().inner(), 1_073_741_824);
let time_units = TimeUnits::new(2_147_483_647);
assert!(matches!(time_units, Some(_)));
assert_eq!(time_units.unwrap().inner(), 2_147_483_647);
let time_units = TimeUnits::new(2_147_483_648);
assert!(matches!(time_units, None));Sourcepub const unsafe fn new_unchecked(value: u32) -> Self
pub const unsafe fn new_unchecked(value: u32) -> Self
Constructs a new TimeUnits from value without checking if less than 2147483648.
§Safety
value must be less than 2147483648.
§Examples
let time_units = unsafe { TimeUnits::new_unchecked(1_073_741_824) };
assert_eq!(time_units.inner(), 1_073_741_824);
let time_units = unsafe { TimeUnits::new_unchecked(2_147_483_647) };
assert_eq!(time_units.inner(), 2_147_483_647);Sourcepub fn from_duration(duration: Duration) -> Option<Self>
pub fn from_duration(duration: Duration) -> Option<Self>
Constructs a new TimeUnits from duration if the total number of nanoseconds
is less than or equal to 3599999998324.
§Examples
let time_units = TimeUnits::from_duration(Duration::from_mins(30));
assert!(matches!(time_units, Some(_)));
assert_eq!(time_units.unwrap().to_duration(), Duration::from_mins(30));
let time_units = TimeUnits::from_duration(Duration::from_nanos(3_599_999_998_324));
assert!(matches!(time_units, Some(_)));
assert_eq!(time_units.unwrap().to_duration(), Duration::from_nanos(3_599_999_998_324));
let time_units = TimeUnits::from_duration(Duration::from_nanos(3_599_999_998_325));
assert!(matches!(time_units, None));Sourcepub const fn is_zero(self) -> bool
pub const fn is_zero(self) -> bool
Returns true if this TimeUnits is Self::ZERO.
§Examples
let time_units = TimeUnits::ZERO;
assert!(time_units.is_zero());
assert_eq!(time_units, TimeUnits::new(0).unwrap());Sourcepub fn to_duration(self) -> Duration
pub fn to_duration(self) -> Duration
Converts this TimeUnits into a Duration.
§Examples
let time_units = TimeUnits::new(1_073_741_824).unwrap();
assert_eq!(time_units.to_duration(), Duration::from_mins(30));
let time_units = TimeUnits::from_duration(Duration::from_mins(30)).unwrap();
assert_eq!(time_units.to_duration(), Duration::from_mins(30));Trait Implementations§
Source§impl Ord for TimeUnits
impl Ord for TimeUnits
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd<TimeUnits> for u32
impl PartialOrd<TimeUnits> for u32
Source§impl PartialOrd<u32> for TimeUnits
impl PartialOrd<u32> for TimeUnits
Source§impl PartialOrd for TimeUnits
impl PartialOrd for TimeUnits
impl Copy for TimeUnits
impl Eq for TimeUnits
impl StructuralPartialEq for TimeUnits
Auto Trait Implementations§
impl Freeze for TimeUnits
impl RefUnwindSafe for TimeUnits
impl Send for TimeUnits
impl Sync for TimeUnits
impl Unpin for TimeUnits
impl UnsafeUnpin for TimeUnits
impl UnwindSafe for TimeUnits
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more