Skip to main content

NtpTimestampGenerator

Trait NtpTimestampGenerator 

Source
pub trait NtpTimestampGenerator {
    // Required methods
    fn init(&mut self);
    fn timestamp_sec(&self) -> u64;
    fn timestamp_subsec_micros(&self) -> u32;

    // Provided method
    fn precision(&self) -> i8 { ... }
}
Expand description

A trait encapsulating timestamp generator’s operations

Since under no_std environment time::now() implementations may be not available, you can implement that trait on an object you want and provide proper system timestamps for the SNTP client. According to specs, all timestamps calculated from UNIX EPOCH “1970-01-01 00:00:00 UTC

Required Methods§

Source

fn init(&mut self)

Initialize timestamp generator state with now system time since UNIX EPOCH. Expected to be called every time before timestamp_sec and timestamp_subsec_micros usage. Basic flow would be the following:

# Timestamp A required
init()
timestamp_sec()
timestamp_subsec_micros()
// ...
# Timestamp B required
init()
timestamp_sec()
timestamp_subsec_micros()
// ... so on
Source

fn timestamp_sec(&self) -> u64

Returns timestamp in seconds since UNIX EPOCH for the initialized generator

Source

fn timestamp_subsec_micros(&self) -> u32

Returns the fractional part of the timestamp in whole micro seconds. That method should not return microseconds since UNIX EPOCH

Provided Methods§

Source

fn precision(&self) -> i8

Returns the precision of the timestamp generator as log2(seconds). For example, -20 means approximately 1 microsecond precision (2^-20 ≈ 0.954 µs). Default: -20 (typical for microsecond-precision clocks).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§