statime/bmc/
acceptable_master.rs1use crate::config::ClockIdentity;
2
3pub trait AcceptableMasterList {
6 fn is_acceptable(&self, identity: ClockIdentity) -> bool;
8}
9
10pub struct AcceptAnyMaster;
13impl AcceptableMasterList for AcceptAnyMaster {
14 fn is_acceptable(&self, _identity: ClockIdentity) -> bool {
15 true
16 }
17}
18
19impl AcceptableMasterList for &[ClockIdentity] {
20 fn is_acceptable(&self, identity: ClockIdentity) -> bool {
21 self.contains(&identity)
22 }
23}
24
25impl<const CAP: usize> AcceptableMasterList for arrayvec::ArrayVec<ClockIdentity, CAP> {
26 fn is_acceptable(&self, identity: ClockIdentity) -> bool {
27 self.contains(&identity)
28 }
29}
30
31#[cfg(feature = "std")]
32impl AcceptableMasterList for std::vec::Vec<ClockIdentity> {
33 fn is_acceptable(&self, identity: ClockIdentity) -> bool {
34 self.contains(&identity)
35 }
36}
37
38#[cfg(feature = "std")]
39impl AcceptableMasterList for std::collections::BTreeSet<ClockIdentity> {
40 fn is_acceptable(&self, identity: ClockIdentity) -> bool {
41 self.contains(&identity)
42 }
43}
44
45#[cfg(feature = "std")]
46impl AcceptableMasterList for std::collections::HashSet<ClockIdentity> {
47 fn is_acceptable(&self, identity: ClockIdentity) -> bool {
48 self.contains(&identity)
49 }
50}
51
52impl<T: AcceptableMasterList> AcceptableMasterList for Option<T> {
53 fn is_acceptable(&self, identity: ClockIdentity) -> bool {
54 match self {
55 Some(list) => list.is_acceptable(identity),
56 None => true,
57 }
58 }
59}