willow25/entry/
subspace_id.rs1use core::fmt;
2
3#[cfg(feature = "dev")]
4use arbitrary::Arbitrary;
5
6use order_theory::{
7 GreatestElement, LeastElement, LowerSemilattice, PredecessorExceptForLeast,
8 SuccessorExceptForGreatest, TryPredecessor, TrySuccessor, UpperSemilattice,
9};
10
11use super::HexFormatter;
12
13pub const SUBSPACE_ID_WIDTH: usize = 32;
17
18wrapper! {
19 #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
30 #[cfg_attr(feature = "dev", derive(Arbitrary))]
31 SubspaceId; [u8; SUBSPACE_ID_WIDTH]
32}
33
34impl fmt::Debug for SubspaceId {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 f.debug_tuple("SubspaceId")
37 .field(&HexFormatter(self.0))
38 .finish()
39 }
40}
41
42impl SubspaceId {
43 pub fn as_bytes(&self) -> &[u8; SUBSPACE_ID_WIDTH] {
47 &self.0
48 }
49}
50
51impl LeastElement for SubspaceId {
52 fn least() -> Self {
53 <[u8; SUBSPACE_ID_WIDTH]>::least().into()
54 }
55}
56
57impl GreatestElement for SubspaceId {
58 fn greatest() -> Self {
59 <[u8; SUBSPACE_ID_WIDTH]>::greatest().into()
60 }
61}
62
63impl LowerSemilattice for SubspaceId {
64 fn greatest_lower_bound(&self, other: &Self) -> Self {
65 self.0.greatest_lower_bound(other.as_bytes()).into()
66 }
67}
68
69impl UpperSemilattice for SubspaceId {
70 fn least_upper_bound(&self, other: &Self) -> Self {
71 self.0.least_upper_bound(other.as_bytes()).into()
72 }
73}
74
75impl TryPredecessor for SubspaceId {
76 fn try_predecessor(&self) -> Option<Self> {
77 self.0.try_predecessor().map(Self)
78 }
79}
80
81impl TrySuccessor for SubspaceId {
82 fn try_successor(&self) -> Option<Self> {
83 self.0.try_successor().map(Self)
84 }
85}
86
87impl PredecessorExceptForLeast for SubspaceId {}
88
89impl SuccessorExceptForGreatest for SubspaceId {}