pub enum TickUnit {
Nanos,
Micros,
Millis,
Secs,
}
Expand description
A TickUnit represents a specific time duration but does not maintain time information, it only helps define the time granularity required to used in various contexts by all kekbit components which share a given channel. For each channel it’s TickUnit will be spcified at creation and will never be changed
Variants§
Nanos
TickUnit representing one thousandth of a microsecond.
Micros
TickUnit representing one thousandth of a millisecond.
Millis
TickUnit representing one thousandth of a second.
Secs
TickUnit representing one second.
Implementations§
Source§impl TickUnit
impl TickUnit
Sourcepub fn id(self) -> u8
pub fn id(self) -> u8
Returns the unique u8 id assigned to every TickUnit. This id it’s used for serialization it would never change.
§Examples
use kekbit_core::tick::TickUnit::*;
assert_eq!(Nanos.id(), 9);
assert_eq!(Micros.id(), 6);
assert_eq!(Millis.id(), 3);
assert_eq!(Secs.id(), 0);
Sourcepub fn convert(self, duration: Duration) -> u64
pub fn convert(self, duration: Duration) -> u64
Returns the total number of tick units contained by this Duration
as a u64.
If the tiemstamp size is longer than 64 bits, it will be truncated to the lower 64 bits
§Examples
use std::time::Duration;
use kekbit_core::tick::TickUnit::*;
let duration = Duration::new(1, 500_000_000); //1 sec and a half
assert_eq!(Nanos.convert(duration), 1_500_000_000);
assert_eq!(Micros.convert(duration), 1_500_000);
assert_eq!(Millis.convert(duration), 1_500);
assert_eq!(Secs.convert(duration), 1);