pub enum TimeScale {
Years,
Days,
Hours,
Minutes,
Seconds,
Milliseconds,
Microseconds,
Nanoseconds,
Ratio(Ratio<NonZeroU32, NonZeroU32>),
}Expand description
๐ Describes the conceptual scale at which time is expressed or interpreted.
๐ phys/time
TimeScale is lightweight, descriptive metadata. It can be used to label
time sources, parameters, or policies without implying exact duration,
normalization, or convertibility between scales.
Calendar-based variants (such as years or days) are symbolic and may depend
on external conventions. The Ratio variant allows expressing custom scales
relative to seconds.
Variantsยง
Years
Days
Hours
Minutes
Seconds
Default time scale.
Milliseconds
Microseconds
Nanoseconds
Ratio(Ratio<NonZeroU32, NonZeroU32>)
A custom, exact time scale expressed as a rational multiple of seconds.
Implementationsยง
Sourceยงimpl TimeScale
impl TimeScale
Sourcepub const fn is_calendar(self) -> bool
pub const fn is_calendar(self) -> bool
Returns true if this scale is calendar-based.
Sourcepub const fn is_subsecond(self) -> bool
pub const fn is_subsecond(self) -> bool
Returns true if this scale is sub-second.
Sourcepub const fn is_second_based(self) -> bool
pub const fn is_second_based(self) -> bool
Returns true if this scale is second-based or finer.
Sourcepub const fn name(self) -> &'static str โ
pub const fn name(self) -> &'static str โ
Returns a short, lowercase name for this time scale.
Sourcepub const fn convert(self, value: u64, target: TimeScale) -> Option<u64> โ
pub const fn convert(self, value: u64, target: TimeScale) -> Option<u64> โ
Converts a numeric value from this scale into target, if both
scales have a fixed, exact ratio to seconds.
Returns None if either scale is calendar-based.
Sourcepub fn convert_simulated(self, value: u64, target: TimeScale) -> u64
pub fn convert_simulated(self, value: u64, target: TimeScale) -> u64
Converts a numeric value from this scale into target
using fixed, simulation-friendly assumptions.
Calendar-based scales are treated as fixed-duration:
- Days = 24 hours
- Years = 365 days
This method never fails and is intended for testing, simulation, and synthetic time sources.
Sourceยงimpl TimeScale
impl TimeScale
Sourcepub const fn new_ratio(num: u32, den: u32) -> Option<Self> โ
pub const fn new_ratio(num: u32, den: u32) -> Option<Self> โ
Creates a ratio-based time scale relative to seconds.
Returns None if either component is zero.
Sourcepub const fn some_ratio(self) -> Option<Ratio<NonZeroU32, NonZeroU32>> โ
pub const fn some_ratio(self) -> Option<Ratio<NonZeroU32, NonZeroU32>> โ
Returns the underlying ratio if this scale is already expressed as one.
Sourcepub const fn to_ratio(self) -> Option<Ratio<NonZeroU32, NonZeroU32>> โ
pub const fn to_ratio(self) -> Option<Ratio<NonZeroU32, NonZeroU32>> โ
Returns the exact ratio of this scale relative to seconds, if fixed-duration.
The returned ratio expresses:
1 unit of this scale = num / den seconds
Calendar-based scales (Days, Years) return None.
Sourcepub const fn to_ratio_simulated(self) -> Ratio<NonZeroU32, NonZeroU32>
pub const fn to_ratio_simulated(self) -> Ratio<NonZeroU32, NonZeroU32>
Returns a simulation-friendly ratio of this scale relative to seconds.
The returned ratio expresses:
1 unit of this scale = num / den seconds
Unlike to_ratio, this method never fails.
Calendar-based scales are mapped to fixed-duration approximations:
Daysare treated as 24-hour days.Yearsare treated as 365-day years.
This method is intended for testing, simulation, and synthetic time sources where deterministic behavior is preferred over civil-time accuracy.
Trait Implementationsยง
impl Copy for TimeScale
impl Eq for TimeScale
Sourceยงimpl PartialEq for TimeScale
impl PartialEq for TimeScale
impl StructuralPartialEq for TimeScale
Auto Trait Implementationsยง
impl Freeze for TimeScale
impl RefUnwindSafe for TimeScale
impl Send for TimeScale
impl Sync for TimeScale
impl Unpin for TimeScale
impl UnsafeUnpin for TimeScale
impl UnwindSafe for TimeScale
Blanket Implementationsยง
Sourceยงimpl<T> AnyExt for T
impl<T> AnyExt for T
Sourceยงfn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Sourceยงfn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Sourceยงfn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.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
Sourceยงimpl<T> ByteSized for T
impl<T> ByteSized for T
Sourceยงconst BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Sourceยงfn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Sourceยงfn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Sourceยงimpl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Sourceยงconst NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Sourceยงfn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Sourceยงfn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Sourceยงfn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Sourceยงfn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Sourceยงfn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSourceยงfn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSourceยงfn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงunsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงunsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงfn mem_as_bytes(&self) -> &[u8] โ
fn mem_as_bytes(&self) -> &[u8] โ
unsafe_slice only.