eryon_core/state/impls/
impl_state.rs1use crate::state::State;
6
7impl<Q> AsRef<Q> for State<Q> {
8 fn as_ref(&self) -> &Q {
9 self.get()
10 }
11}
12
13impl<Q> AsMut<Q> for State<Q> {
14 fn as_mut(&mut self) -> &mut Q {
15 self.get_mut()
16 }
17}
18
19impl<Q> core::borrow::Borrow<Q> for State<Q> {
20 fn borrow(&self) -> &Q {
21 self.get()
22 }
23}
24
25impl<Q> core::borrow::BorrowMut<Q> for State<Q> {
26 fn borrow_mut(&mut self) -> &mut Q {
27 self.get_mut()
28 }
29}
30
31impl<Q> core::ops::Deref for State<Q> {
32 type Target = Q;
33
34 fn deref(&self) -> &Self::Target {
35 self.get()
36 }
37}
38
39impl<Q> core::ops::DerefMut for State<Q> {
40 fn deref_mut(&mut self) -> &mut Self::Target {
41 self.get_mut()
42 }
43}
44
45impl<Q> PartialEq<Q> for State<Q>
49where
50 Q: PartialEq,
51{
52 fn eq(&self, other: &Q) -> bool {
53 self.get().eq(other)
54 }
55}
56
57impl<'a, Q> PartialEq<&'a Q> for State<Q>
58where
59 Q: PartialEq,
60{
61 fn eq(&self, other: &&'a Q) -> bool {
62 self.get().eq(*other)
63 }
64}
65
66impl<'a, Q> PartialEq<&'a mut Q> for State<Q>
67where
68 Q: PartialEq,
69{
70 fn eq(&self, other: &&'a mut Q) -> bool {
71 self.get().eq(*other)
72 }
73}
74
75impl<Q> PartialOrd<Q> for State<Q>
76where
77 Q: PartialOrd,
78{
79 fn partial_cmp(&self, other: &Q) -> Option<core::cmp::Ordering> {
80 self.get().partial_cmp(other)
81 }
82}
83
84impl<'a, Q> PartialOrd<&'a Q> for State<Q>
85where
86 Q: PartialOrd,
87{
88 fn partial_cmp(&self, other: &&'a Q) -> Option<core::cmp::Ordering> {
89 self.get().partial_cmp(*other)
90 }
91}
92
93impl<'a, Q> PartialOrd<&'a mut Q> for State<Q>
94where
95 Q: PartialOrd,
96{
97 fn partial_cmp(&self, other: &&'a mut Q) -> Option<core::cmp::Ordering> {
98 self.get().partial_cmp(*other)
99 }
100}
101
102impl<Q> From<Q> for State<Q> {
106 fn from(state: Q) -> Self {
107 State(state)
108 }
109}
110
111unsafe impl<Q> core::marker::Send for State<Q> where Q: core::marker::Send {}
115
116unsafe impl<Q> core::marker::Sync for State<Q> where Q: core::marker::Sync {}
117
118macro_rules! impl_fmt {
119 ($wrap:ident<$T:ident>($($trait:ident),* $(,)?)) => {
120 $(
121 impl_fmt!(@impl $wrap<$T>($trait));
122 )*
123 };
124 (@impl $wrap:ident<$T:ident>($trait:ident)) => {
125 impl<$T> ::core::fmt::$trait for State<$T>
126 where
127 $T: ::core::fmt::$trait,
128 {
129 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
130 ::core::fmt::$trait::fmt(self.get(), f)
131 }
132 }
133 };
134}
135
136impl_fmt! {
137 State<Q>(
138 Binary, Debug, Display, LowerExp, LowerHex, Octal, UpperExp, UpperHex
139 )
140}