rstm_state/impls/
impl_state.rs1use crate::state::State;
6
7use crate::traits::{RawState, StateRepr};
8
9impl<Q> StateRepr<Q> for State<Q>
10where
11 Q: RawState,
12{
13 type Repr<_V: RawState> = State<_V>;
14
15 seal! {}
16
17 fn get(&self) -> &Q {
18 &self.0
19 }
20
21 fn get_mut(&mut self) -> &mut Q {
22 &mut self.0
23 }
24
25 fn view(&self) -> Self::Repr<&Q> {
26 State::new(self.get())
27 }
28
29 fn view_mut(&mut self) -> Self::Repr<&mut Q> {
30 State::new(self.get_mut())
31 }
32}
33
34impl<Q> AsRef<Q> for State<Q> {
35 fn as_ref(&self) -> &Q {
36 &self.0
37 }
38}
39
40impl<Q> AsMut<Q> for State<Q> {
41 fn as_mut(&mut self) -> &mut Q {
42 &mut self.0
43 }
44}
45
46impl<Q> core::borrow::Borrow<Q> for State<Q> {
47 fn borrow(&self) -> &Q {
48 &self.0
49 }
50}
51
52impl<Q> core::borrow::BorrowMut<Q> for State<Q> {
53 fn borrow_mut(&mut self) -> &mut Q {
54 &mut self.0
55 }
56}
57
58impl<Q> core::ops::Deref for State<Q> {
59 type Target = Q;
60
61 fn deref(&self) -> &Self::Target {
62 &self.0
63 }
64}
65
66impl<Q> core::ops::DerefMut for State<Q> {
67 fn deref_mut(&mut self) -> &mut Self::Target {
68 &mut self.0
69 }
70}
71
72impl<Q> PartialEq<Q> for State<Q>
76where
77 Q: PartialEq,
78{
79 fn eq(&self, other: &Q) -> bool {
80 self.0.eq(other)
81 }
82}
83
84impl<'a, Q> PartialEq<&'a Q> for State<Q>
85where
86 Q: PartialEq,
87{
88 fn eq(&self, other: &&'a Q) -> bool {
89 self.0.eq(*other)
90 }
91}
92
93impl<'a, Q> PartialEq<&'a mut Q> for State<Q>
94where
95 Q: PartialEq,
96{
97 fn eq(&self, other: &&'a mut Q) -> bool {
98 self.0.eq(*other)
99 }
100}
101
102impl<Q> PartialOrd<Q> for State<Q>
103where
104 Q: PartialOrd,
105{
106 fn partial_cmp(&self, other: &Q) -> Option<core::cmp::Ordering> {
107 self.0.partial_cmp(other)
108 }
109}
110
111impl<'a, Q> PartialOrd<&'a Q> for State<Q>
112where
113 Q: PartialOrd,
114{
115 fn partial_cmp(&self, other: &&'a Q) -> Option<core::cmp::Ordering> {
116 self.0.partial_cmp(*other)
117 }
118}
119
120impl<'a, Q> PartialOrd<&'a mut Q> for State<Q>
121where
122 Q: PartialOrd,
123{
124 fn partial_cmp(&self, other: &&'a mut Q) -> Option<core::cmp::Ordering> {
125 self.0.partial_cmp(*other)
126 }
127}
128
129impl<Q> From<Q> for State<Q> {
133 fn from(state: Q) -> Self {
134 State(state)
135 }
136}
137
138unsafe impl<Q> core::marker::Send for State<Q> where Q: core::marker::Send {}
142
143unsafe impl<Q> core::marker::Sync for State<Q> where Q: core::marker::Sync {}
144
145contained::fmt_wrapper! {
146 impl State<Q> {
147 Binary,
148 Debug,
149 Display,
150 LowerExp,
151 LowerHex,
152 Octal,
153 UpperExp,
154 UpperHex
155 }
156}