[][src]Enum kekbit::core::TickUnit

pub enum TickUnit {
    Nanos,
    Micros,
    Millis,
    Secs,
}

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.

Methods

impl TickUnit[src]

pub fn id(self) -> u8[src]

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

pub fn from_id(id: u8) -> TickUnit[src]

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

pub fn convert(self, duration: Duration) -> u64[src]

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

pub fn nix_time(self) -> u64[src]

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

impl Clone for TickUnit[src]

impl Copy for TickUnit[src]

impl Debug for TickUnit[src]

impl Eq for TickUnit[src]

impl PartialEq<TickUnit> for TickUnit[src]

impl StructuralEq for TickUnit[src]

impl StructuralPartialEq for TickUnit[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.