tiktok 0.0.2

Logical Clocks for Temporal Ordering in Distributed Systems
Documentation
//Logical Clock

use std::fmt::{Formatter, Display, Error};


#[derive(Debug,Clone,Eq,PartialEq,PartialOrd,Ord)]
pub struct Clock {
    logical: u128
}

impl Clock {
    pub fn new() -> Clock {
        Clock {
            logical: 0
        }
    }

    //increase time
    pub fn increment(&mut self) { self.logical += 1 }

    //get current time
    pub fn now(&self) -> u128 { self.logical }
}


impl Display for Clock {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        f.write_str(&format!("current logical time is {}", self.logical))
    }
}


#[cfg(test)]
mod tests {
    use super::Clock;

    #[test]
    fn it_works() {
        let mut c = Clock::new();
        println!("{:?}", c);
        c.increment();
        println!("{:?}", c);
        c.increment();
        c.increment();
        println!("{:?}", c);
        assert_eq!(2 + 2, 4);
    }
}