Trait local_clock::LocalClock
source · pub trait LocalClock: Send {
// Required methods
fn get_time(&mut self) -> LocalClockTime;
fn set_time(&mut self, new_time: LocalClockTime);
}
Expand description
A local real-time clock, hanging-off the platform’s global real-time clock.
One way to think about LocalClock
is that it matches the semantics of
the POSIX methods clock_gettime
and clock_settime
when backed by
CLOCK_REALTIME
, except setting the time on a LocalClock
will only
affect that particular instance (as opposed to changing the global system
time).
NOTE: These methods may be invoked fairly often, and as such, implementors should ensure these methods do not block!
Required Methods§
sourcefn get_time(&mut self) -> LocalClockTime
fn get_time(&mut self) -> LocalClockTime
Return the current clock time.
§First call
If set_time
has yet to be called, the LocalClock
trait makes no
guarantees as to what time get_time
will return!
Conceptually, this would be akin to pulling the real-time-block battery from a physical machine, thereby resetting the clock to its “default” state - whatever that might be.
A simple implementation would be to just return a hard-coded, fixed value, corresponding to some arbitrary date.
…that being said, a far more useful implementation would be to simply
report the platform’s current real time. That way, even if set_time
never gets invoked, (e.g: as a result of communicating with a NTP
server, a synthetic real-time assist virtual device, manual user input,
etc…), the reported real time will still be reasonably close to the
current date.
§Subsequent calls
On subsequent calls to this function, this method MUST return the sum of
the previously set time set via set_time
, plus the wall-clock time
that has elapsed since.
NOTE: implementations SHOULD ensure that real time continues to tick even when the device / platform itself has shutdown / been paused.
sourcefn set_time(&mut self, new_time: LocalClockTime)
fn set_time(&mut self, new_time: LocalClockTime)
Set the current clock time.