Skip to main content

ClockSync

Trait ClockSync 

Source
pub trait ClockSync {
    // Required methods
    async fn wait_for_tick(&self) -> ClockSyncTick;
    fn now_local(&self) -> OffsetDateTime;
    fn set_offset_minutes(&self, minutes: i32);
    fn offset_minutes(&self) -> i32;
    fn set_tick_interval(&self, interval: Option<Duration>);
    fn set_speed(&self, speed_multiplier: f32);
    fn set_utc_time(&self, unix_seconds: UnixSeconds);
}
Expand description

Platform-agnostic ClockSync operation contract.

Platform crates can use this trait for generic clock control helpers while keeping constructors on the concrete type.

§Example

use device_envoy_core::clock_sync::{ClockSync, h12_m_s};

async fn log_one_tick(clock_sync: &impl ClockSync) {
    let clock_sync_tick = clock_sync.wait_for_tick().await;
    let (hours, minutes, seconds) = h12_m_s(&clock_sync_tick.local_time);
    let _ = (hours, minutes, seconds);
}

Required Methods§

Source

async fn wait_for_tick(&self) -> ClockSyncTick

Wait for and return the next tick after sync.

See the ClockSync trait documentation for usage examples.

Source

fn now_local(&self) -> OffsetDateTime

Get the current local time without waiting for a tick.

Source

fn set_offset_minutes(&self, minutes: i32)

Update the UTC offset used for local time.

Source

fn offset_minutes(&self) -> i32

Get the current UTC offset in minutes.

Source

fn set_tick_interval(&self, interval: Option<Duration>)

Set the tick interval. Use None to disable periodic ticks.

This uses embassy_time::Duration for interval timing.

Source

fn set_speed(&self, speed_multiplier: f32)

Update the speed multiplier (1.0 = real time).

Source

fn set_utc_time(&self, unix_seconds: UnixSeconds)

Manually set the current UTC time and mark the clock as synced.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§