rstm_state/traits/
halting.rs1use crate::traits::RawState;
6
7pub trait Halt {
9 private! {}
10
11 fn is_halted(&self) -> bool;
12}
13
14pub trait HaltState: Halt + RawState {
15 private! {}
16}
17
18use crate::state::State;
22
23impl<Q> HaltState for Q
24where
25 Q: Halt + RawState,
26{
27 seal! {}
28}
29
30impl<Q> Halt for State<Q>
31where
32 Q: RawState + Halt,
33{
34 seal!();
35
36 fn is_halted(&self) -> bool {
37 self.0.is_halted()
38 }
39}
40
41impl<Q> Halt for &Q
42where
43 Q: Halt,
44{
45 seal!();
46
47 fn is_halted(&self) -> bool {
48 <Q as Halt>::is_halted(*self)
49 }
50}
51
52impl<Q> Halt for &mut Q
53where
54 Q: Halt,
55{
56 seal!();
57
58 fn is_halted(&self) -> bool {
59 <Q as Halt>::is_halted(*self)
60 }
61}
62
63impl<Q> Halt for Option<Q>
64where
65 Q: RawState,
66{
67 seal!();
68
69 fn is_halted(&self) -> bool {
70 self.is_none()
71 }
72}
73
74impl<Q> Halt for Option<State<Q>>
75where
76 Q: RawState,
77{
78 seal!();
79
80 fn is_halted(&self) -> bool {
81 self.is_none()
82 }
83}
84
85macro_rules! impl_num_haltable {
86 (#[impl($trait:ident)] $($t:ty),* $(,)?) => {
87 $(
88 impl $trait for $t {
89 seal!();
90
91 fn is_halted(&self) -> bool {
92 *self == <$t>::MAX
93 }
94 }
95 )*
96 };
97}
98
99impl_num_haltable!(
100 #[impl(Halt)]
101 u8, u16, u32, u64, u128, usize,
102 i8, i16, i32, i64, i128, isize,
103);
104
105impl Halt for f32 {
106 seal!();
107
108 fn is_halted(&self) -> bool {
109 self.is_infinite() || self.is_nan()
110 }
111}
112
113impl Halt for f64 {
114 seal!();
115
116 fn is_halted(&self) -> bool {
117 self.is_infinite() || self.is_nan()
118 }
119}