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§
Sourceasync fn wait_for_tick(&self) -> ClockSyncTick
async fn wait_for_tick(&self) -> ClockSyncTick
Wait for and return the next tick after sync.
See the ClockSync trait documentation for usage examples.
Sourcefn now_local(&self) -> OffsetDateTime
fn now_local(&self) -> OffsetDateTime
Get the current local time without waiting for a tick.
Sourcefn set_offset_minutes(&self, minutes: i32)
fn set_offset_minutes(&self, minutes: i32)
Update the UTC offset used for local time.
Sourcefn offset_minutes(&self) -> i32
fn offset_minutes(&self) -> i32
Get the current UTC offset in minutes.
Sourcefn set_tick_interval(&self, interval: Option<Duration>)
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.
Sourcefn set_utc_time(&self, unix_seconds: UnixSeconds)
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.