rstm_core/state/halt/
impl_halt.rs1use super::Halt;
6use crate::state::{RawState, State};
7
8impl<Q> Halt<Q> {
9 pub fn new(halt: Q) -> Self {
10 Self(halt)
11 }
12 #[inline]
13 pub fn get(self) -> Q {
15 self.0
16 }
17 pub const fn get_ref(&self) -> &Q {
19 &self.0
20 }
21 pub fn get_mut(&mut self) -> &mut Q {
23 &mut self.0
24 }
25 pub fn replace(&mut self, halt: Q) -> Q {
28 core::mem::replace(&mut self.0, halt)
29 }
30 pub fn reset(&mut self)
32 where
33 Q: Default,
34 {
35 self.set(Default::default());
36 }
37 pub fn set(&mut self, halt: Q) {
39 self.0 = halt;
40 }
41 pub fn swap<S>(&mut self, other: &mut S)
43 where
44 S: RawState<Q = Q>,
45 {
46 core::mem::swap(&mut self.0, other.get_mut());
47 }
48 pub fn take(&mut self) -> Q
51 where
52 Q: Default,
53 {
54 core::mem::take(&mut self.0)
55 }
56 pub fn as_state(&self) -> State<Halt<&Q>> {
59 State(Halt(&self.0))
60 }
61 pub fn as_state_mut(&mut self) -> State<Halt<&mut Q>> {
64 State(Halt(&mut self.0))
65 }
66 pub fn into_state(self) -> State<Halt<Q>> {
68 State(self)
69 }
70 pub fn view(&self) -> Halt<&Q> {
72 Halt(&self.0)
73 }
74 pub fn view_mut(&mut self) -> Halt<&mut Q> {
76 Halt(&mut self.0)
77 }
78}
79
80impl<'a, Q> Halt<&'a Q> {
81 pub fn cloned(&self) -> Halt<Q>
82 where
83 Q: Clone,
84 {
85 Halt(self.0.clone())
86 }
87
88 pub fn copied(&self) -> Halt<Q>
89 where
90 Q: Copy,
91 {
92 Halt(*self.0)
93 }
94}
95
96impl<'a, Q> Halt<&'a mut Q> {
97 pub fn cloned(&self) -> Halt<Q>
98 where
99 Q: Clone,
100 {
101 Halt(self.0.clone())
102 }
103
104 pub fn copied(&self) -> Halt<Q>
105 where
106 Q: Copy,
107 {
108 Halt(*self.0)
109 }
110}
111
112impl<Q> From<State<Q>> for Halt<Q> {
113 fn from(State(state): State<Q>) -> Self {
114 Self(state)
115 }
116}
117
118impl<Q> From<Halt<Q>> for State<Q> {
119 fn from(Halt(state): Halt<Q>) -> Self {
120 Self(state)
121 }
122}