pub struct Versioned<T> { /* private fields */ }Expand description
A value and the version it is currently at.
Both ends of a connection hold one. The sender calls commit, the
receiver calls apply, and the version and fingerprints travel between
them inside a VersionedDelta.
Implementations§
Source§impl<T> Versioned<T>
impl<T> Versioned<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Starts a value at version 0.
Both ends have to start from the same value; sending a Versioned<T>
whole is how a receiver catches up after a Rejected.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Takes the value back out, discarding the version.
Source§impl<T: Fingerprint> Versioned<T>
impl<T: Fingerprint> Versioned<T>
Sourcepub fn fingerprint(&self) -> u64
pub fn fingerprint(&self) -> u64
The fingerprint of the value as it stands.
Source§impl<T: Delta + Fingerprint + Clone> Versioned<T>
impl<T: Delta + Fingerprint + Clone> Versioned<T>
Sourcepub fn commit(&mut self, new: T) -> Option<VersionedDelta<T::Output>>
pub fn commit(&mut self, new: T) -> Option<VersionedDelta<T::Output>>
Moves to new and produces the delta that gets a peer here.
Returns None when nothing changed, in which case the version does
not advance either — an update that would do nothing costs no message
and no number.
T: Clone is needed because Delta::delta consumes both sides and
the new value has to be kept as well as diffed.
Source§impl<T: Delta + Fingerprint> Versioned<T>
impl<T: Delta + Fingerprint> Versioned<T>
Sourcepub fn apply(
&mut self,
delta: VersionedDelta<T::Output>,
) -> Result<Applied, Rejected>
pub fn apply( &mut self, delta: VersionedDelta<T::Output>, ) -> Result<Applied, Rejected>
Applies a delta, or explains why it does not belong here.
A delta that has already been applied is reported as
Applied::Stale and does nothing, so duplicate delivery is safe. A
Rejected leaves the version untouched, which means a later delta in
the same stream will fail too rather than papering over the hole — the
only way forward is to replace the whole value.