Clock

Trait Clock 

Source
pub trait Clock {
    type IncrementError: Error;
    type WitnessError: Error;

    // Required methods
    fn time(&self) -> Time;
    fn increment(&mut self) -> Result<Time, Self::IncrementError>;
    fn witness(&mut self, other: Time) -> Result<(), Self::WitnessError>;
}
Expand description

A Lamport clock.

See the module documentation, for information on why this is needed.

Required Associated Types§

Source

type IncrementError: Error

The Error returned, when trying to increment this clock.

Source

type WitnessError: Error

The Error returned, when trying to witness this clock.

Required Methods§

Source

fn time(&self) -> Time

Get the current value of this clock.

Source

fn increment(&mut self) -> Result<Time, Self::IncrementError>

Return the current value and increment it internally.

§Errors

If the increment operation failed.

Source

fn witness(&mut self, other: Time) -> Result<(), Self::WitnessError>

Update our clock based on another processes clock’s value, we “witnessed”.

We effectively try to keep our clock at other + 1 time, so that we are always ahead by one time unit.

§Examples
use git_bug::replica::entity::lamport::{Clock, Time, mem};
let mut clock = mem::MemClock::new();
assert_eq!(1, clock.time().value());
assert_eq!(1, clock.increment()?.value());

clock.witness(Time::from(42));
assert_eq!(42, clock.time().value());

clock.witness(Time::from(30));
assert_eq!(Time::from(42), clock.time());
§Errors

If the witness operation failed.

Implementors§