1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::interfaces::DEFAULT_EPOCH_STABILITY_DEPTH;
use serde::{Deserialize, Serialize};
use std::fmt;

/// epoch stability depth
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct EpochStabilityDepth(u32);

impl fmt::Display for EpochStabilityDepth {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        self.0.fmt(f)
    }
}

impl Default for EpochStabilityDepth {
    fn default() -> Self {
        Self(DEFAULT_EPOCH_STABILITY_DEPTH)
    }
}

impl From<u32> for EpochStabilityDepth {
    fn from(v: u32) -> Self {
        Self(v)
    }
}

impl From<EpochStabilityDepth> for u32 {
    fn from(v: EpochStabilityDepth) -> Self {
        v.0
    }
}

#[cfg(test)]
mod test {
    use super::*;
    use quickcheck::{Arbitrary, Gen};

    impl Arbitrary for EpochStabilityDepth {
        fn arbitrary<G: Gen>(g: &mut G) -> Self {
            EpochStabilityDepth(Arbitrary::arbitrary(g))
        }
    }
}