pub struct ClockSync { /* private fields */ }Expand description
NTP-like clock synchronization between client and server.
Implementations§
Source§impl ClockSync
impl ClockSync
pub fn new() -> Self
pub fn state(&self) -> SyncState
pub fn estimated_offset_ms(&self) -> i64
pub fn estimated_rtt_ms(&self) -> f64
pub fn is_synchronized(&self) -> bool
pub fn set_sync_interval(&mut self, interval_ms: u64)
pub fn set_convergence_rate(&mut self, rate: f64)
Sourcepub fn add_sample(&mut self, sample: ClockSyncSample)
pub fn add_sample(&mut self, sample: ClockSyncSample)
Add a new synchronization sample.
Sourcepub fn local_to_remote(&self, local_ms: u64) -> u64
pub fn local_to_remote(&self, local_ms: u64) -> u64
Convert a local timestamp to estimated remote time.
Sourcepub fn remote_to_local(&self, remote_ms: u64) -> u64
pub fn remote_to_local(&self, remote_ms: u64) -> u64
Convert a remote timestamp to estimated local time.
Sourcepub fn needs_sync(&self, current_time_ms: u64) -> bool
pub fn needs_sync(&self, current_time_ms: u64) -> bool
Whether it’s time to send another sync request.
Sourcepub fn on_sync_sent(&mut self, time_ms: u64)
pub fn on_sync_sent(&mut self, time_ms: u64)
Mark that we sent a sync request.
Sourcepub fn update_drift(&mut self, current_time_ms: u64)
pub fn update_drift(&mut self, current_time_ms: u64)
Update drift estimation. Call periodically.
pub fn drift_rate(&self) -> f64
pub fn sample_count(&self) -> usize
pub fn reset(&mut self)
Sourcepub fn confidence(&self) -> f64
pub fn confidence(&self) -> f64
Get the confidence of the current estimate (0.0 to 1.0).
Auto Trait Implementations§
impl Freeze for ClockSync
impl RefUnwindSafe for ClockSync
impl Send for ClockSync
impl Sync for ClockSync
impl Unpin for ClockSync
impl UnsafeUnpin for ClockSync
impl UnwindSafe for ClockSync
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.