Enum TickUnit

Source
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

Source

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);
Source

pub fn from_id(id: u8) -> TickUnit

Returns the tick unit with the given id

§Arguments
  • id - The identifier of the tick unit as u8. In the curent kekbit version it must be 0, 3, 6 or 9
§Panics

If the specified id has no tick unit attached

Source

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);
Source

pub fn nix_time(self) -> u64

Returns the difference, measured in the current tick unit, between the current time and midnight, January 1, 1970 UTC.

§Examples
use kekbit_core::tick::TickUnit::*;

println!("{}ms since January 1, 1970 UTC", Millis.nix_time());

Trait Implementations§

Source§

impl Clone for TickUnit

Source§

fn clone(&self) -> TickUnit

Returns a duplicate 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 TickUnit

Source§

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

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

impl PartialEq for TickUnit

Source§

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

Source§

impl Eq for TickUnit

Source§

impl StructuralPartialEq for TickUnit

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.