Skip to main content

Versioned

Struct Versioned 

Source
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>

Source

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.

Source

pub fn version(&self) -> u64

The version this value is at.

Source

pub fn get(&self) -> &T

Borrows the value.

Source

pub fn into_inner(self) -> T

Takes the value back out, discarding the version.

Source§

impl<T: Fingerprint> Versioned<T>

Source

pub fn fingerprint(&self) -> u64

The fingerprint of the value as it stands.

Source§

impl<T: Delta + Fingerprint + Clone> Versioned<T>

Source

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>

Source

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.

Trait Implementations§

Source§

impl<T: Clone> Clone for Versioned<T>

Source§

fn clone(&self) -> Versioned<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Versioned<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for Versioned<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Eq> Eq for Versioned<T>

Source§

impl<T: PartialEq> PartialEq for Versioned<T>

Source§

fn eq(&self, other: &Versioned<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T> Serialize for Versioned<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Versioned<T>

Auto Trait Implementations§

§

impl<T> Freeze for Versioned<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Versioned<T>
where T: RefUnwindSafe,

§

impl<T> Send for Versioned<T>
where T: Send,

§

impl<T> Sync for Versioned<T>
where T: Sync,

§

impl<T> Unpin for Versioned<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Versioned<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Versioned<T>
where T: UnwindSafe,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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 = !

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.