1use num_traits::{Zero, One};
2use std::ops::AddAssign;
3use rand::{Rand, random};
4
5pub struct IncrementalStamper<S, C> {
6 site: S,
7 clock: C
8}
9impl<S, C> IncrementalStamper<S, C> where S: Copy, C: AddAssign + One + Copy {
10 pub fn stamp(&mut self) -> (S, C) {
11 self.clock += C::one();
12 (self.site, self.clock)
13 }
14}
15impl<S, C> IncrementalStamper<S, C> where S: Rand, C: Zero{
16 pub fn init_random() -> IncrementalStamper<S, C> {
17 IncrementalStamper {
18 site: random(),
19 clock: C::zero()
20 }
21 }
22}
23impl<S, C> IncrementalStamper<S, C> where C: Zero{
24 pub fn init_with_site(site: S) -> IncrementalStamper<S, C> {
25 IncrementalStamper {
26 site: site,
27 clock: C::zero()
28 }
29 }
30}