SyncTracker

Struct SyncTracker 

Source
pub struct SyncTracker { /* private fields */ }
Available on crate feature sync only.
Expand description

Sync tracker state (each endpoint maintains this)

Tracks version numbers for synchronization:

  • current_num: Version of current local state
  • last_sent_num: Version of last state we sent to peer
  • last_acked: Highest version our peer acknowledged receiving
  • peer_state_num: Highest version we’ve received from peer

Implementations§

Source§

impl SyncTracker

Source

pub fn new() -> Self

Create a new sync tracker

Source

pub fn with_initial_version(version: u64) -> Self

Create a tracker with initial state

Source

pub fn current_version(&self) -> u64

Get current local state version

Source

pub fn last_sent_version(&self) -> u64

Get last sent version

Source

pub fn last_acked_version(&self) -> u64

Get highest version acked by peer

Source

pub fn peer_version(&self) -> u64

Get highest version received from peer

Source

pub fn has_pending_updates(&self) -> bool

Check if we have pending updates to send

Source

pub fn needs_ack(&self) -> bool

Check if we need to send an ack

Source

pub fn is_synchronized(&self) -> bool

Check if the state is in sync with peer

Source

pub fn bump_version(&mut self) -> u64

Bump local state version (call when local state changes)

Source

pub fn record_sent(&mut self, sent_version: u64)

Record that we sent a message

Returns the version number that was marked as sent.

Source

pub fn process_incoming(&mut self, msg: &SyncMessage) -> bool

Process an incoming sync message

Updates:

  • peer_state_num from the sender’s current version
  • last_acked from the sender’s ack field

Returns true if the message contained new state (not just an ack).

Source

pub fn create_message(&self, diff: Vec<u8>, base_state_num: u64) -> SyncMessage

Create a sync message with current state info

The caller should fill in the diff payload.

Source

pub fn create_ack(&self) -> SyncMessage

Create an ack-only message

Source

pub fn reset(&mut self)

Reset the tracker to initial state

Source

pub fn diff_base_version(&self) -> u64

Get the base state number that should be used for diff computation

This is the last version we know the peer has acknowledged.

Trait Implementations§

Source§

impl Clone for SyncTracker

Source§

fn clone(&self) -> SyncTracker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SyncTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SyncTracker

Source§

fn default() -> SyncTracker

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V