pub struct TimeSync { /* private fields */ }Expand description
Maintains a sliding window of timestamp samples and computes a linear model mapping device ticks to host time.
Implementations§
Source§impl TimeSync
impl TimeSync
Sourcepub fn update(&mut self, dev_ticks: u64, host: Instant)
pub fn update(&mut self, dev_ticks: u64, host: Instant)
Record a new (device_ticks, host_instant) sample.
Sourcepub fn samples(&self) -> impl Iterator<Item = (u64, Instant)> + '_
pub fn samples(&self) -> impl Iterator<Item = (u64, Instant)> + '_
Iterator over the samples contained in the sliding window.
Sourcepub fn origin_instant(&self) -> Option<Instant>
pub fn origin_instant(&self) -> Option<Instant>
Access the origin instant if at least one sample has been recorded.
Sourcepub fn origin_system(&self) -> Option<SystemTime>
pub fn origin_system(&self) -> Option<SystemTime>
Access the origin system time if available.
Sourcepub fn coefficients(&self) -> (f64, f64)
pub fn coefficients(&self) -> (f64, f64)
Retrieve the linear fit coefficients.
Sourcepub fn sample_bounds(&self) -> Option<((u64, Instant), (u64, Instant))>
pub fn sample_bounds(&self) -> Option<((u64, Instant), (u64, Instant))>
Return the first and last sample retained in the window.
Sourcepub fn fit(&mut self, freq_hz: Option<f64>) -> Option<(f64, f64)>
pub fn fit(&mut self, freq_hz: Option<f64>) -> Option<(f64, f64)>
Fit a linear model mapping device ticks to host seconds relative to the
first recorded instant. Returns the updated (a, b) coefficients when
enough samples are available.
Sourcepub fn to_host_time(&self, dev_ticks: u64) -> SystemTime
pub fn to_host_time(&self, dev_ticks: u64) -> SystemTime
Convert device ticks into a SystemTime using the fitted model.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TimeSync
impl RefUnwindSafe for TimeSync
impl Send for TimeSync
impl Sync for TimeSync
impl Unpin for TimeSync
impl UnwindSafe for TimeSync
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more