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§
Sourcetype IncrementError: Error
type IncrementError: Error
The Error returned, when trying to increment
this clock.
Sourcetype WitnessError: Error
type WitnessError: Error
The Error returned, when trying to witness this
clock.
Required Methods§
Sourcefn increment(&mut self) -> Result<Time, Self::IncrementError>
fn increment(&mut self) -> Result<Time, Self::IncrementError>
Sourcefn witness(&mut self, other: Time) -> Result<(), Self::WitnessError>
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.