1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
appellation: impl_rule <module>
authors: @FL03
*/
use super::{Rule, RuleBuilder};
use rstm_core::{Direction, Head, Tail};
use rstm_state::{RawState, State};
impl<Q, A> Rule<Q, A>
where
Q: RawState,
{
pub const fn new() -> RuleBuilder<Q, A> {
RuleBuilder::new()
}
/// returns an immutable reference to the [Head]
pub const fn head(&self) -> &Head<Q, A> {
&self.head
}
/// returns a mutable reference to the [Head]
pub const fn head_mut(&mut self) -> &mut Head<Q, A> {
&mut self.head
}
/// returns an immutable reference to the [Tail] of the [Instruction]
pub const fn tail(&self) -> &Tail<Q, A> {
&self.tail
}
/// returns a mutable reference to the [Tail] of the [Instruction]
pub const fn tail_mut(&mut self) -> &mut Tail<Q, A> {
&mut self.tail
}
/// returns an instance of the [Head] whose elements are immutable references
pub const fn head_view(&self) -> Head<&'_ Q, &'_ A> {
self.head().view()
}
/// returns an instance of the [Tail] whose elements are immutable references
pub const fn tail_view(&self) -> Tail<&'_ Q, &'_ A> {
self.tail().view()
}
/// returns the direction of the shift
pub const fn direction(&self) -> Direction {
self.tail().direction()
}
/// returns the current [State] of the system
pub const fn state(&self) -> &State<Q> {
self.head().state()
}
/// returns a mutable reference to the current [State] of the system
pub const fn state_mut(&mut self) -> &mut State<Q> {
self.head_mut().state_mut()
}
/// returns the symbol of the [Head]
pub const fn symbol(&self) -> &A {
self.head().symbol()
}
/// returns a mutable reference to the symbol of the [`Head`]
pub const fn symbol_mut(&mut self) -> &mut A {
self.head_mut().symbol_mut()
}
/// returns the next [State] of the system
pub const fn next_state(&self) -> &State<Q> {
self.tail().state()
}
/// returns a mutable reference to the next [State] of the system
pub const fn next_state_mut(&mut self) -> &mut State<Q> {
self.tail_mut().state_mut()
}
/// returns the symbol which will be written by the [Head]
pub const fn next_symbol(&self) -> &A {
self.tail().symbol()
}
/// returns a mutable reference to the next symbol
pub const fn next_symbol_mut(&mut self) -> &mut A {
self.tail_mut().symbol_mut()
}
/// updates the current [Direction] and returns a mutable reference to the [Rule]
pub fn set_direction(&mut self, direction: Direction) -> &mut Self {
self.tail_mut().set_direction(direction);
self
}
/// update the current symbol and return a mutable reference to the [Rule]
pub fn set_symbol(&mut self, symbol: A) -> &mut Self {
self.head_mut().set_symbol(symbol);
self
}
/// updates the current [State] and returns a mutable reference to the [Rule]
pub fn set_state(&mut self, state: Q) -> &mut Self {
self.head_mut().set_state(state);
self
}
/// updates the current [State] and returns a mutable reference to the [Rule]
pub fn set_next_state(&mut self, state: Q) -> &mut Self {
self.tail_mut().set_state(state);
self
}
/// updates the next symbol and returns a mutable reference to the [Rule]
pub fn set_next_symbol(&mut self, symbol: A) -> &mut Self {
self.tail_mut().set_symbol(symbol);
self
}
/// updates the current [State] and symbol and returns a mutable reference to the [Rule]
pub fn set_head(&mut self, state: Q, symbol: A) -> &mut Self {
self.head_mut().set_state(state);
self.head_mut().set_symbol(symbol);
self
}
/// updates the current [State] and symbol and returns a mutable reference to the [Rule]
pub fn set_tail(&mut self, state: Q, symbol: A) -> &mut Self {
self.tail_mut().set_state(state);
self.tail_mut().set_symbol(symbol);
self
}
/// returns the next [Head] of the system
pub const fn next_head(&self) -> Head<&'_ Q, &'_ A> {
self.tail().as_head()
}
/// consumes the current object and returns the next [Head] of the system
pub fn into_next_head(self) -> Head<Q, A> {
self.tail.into_head()
}
/// returns the value which for which the current object will be replaced with
pub const fn write_symbol(&self) -> &A {
self.tail().symbol()
}
/// consumes the current object and returns a 2-tuple consisting of the [Head] and [Tail]
pub fn into_tuple(self) -> (Head<Q, A>, Tail<Q, A>) {
(self.head, self.tail)
}
/// returns a new instance of the [`Rule`] with cloned elements
pub fn cloned(&self) -> Rule<Q, A>
where
Q: Clone,
A: Clone,
{
Rule {
head: self.head.clone(),
tail: self.tail.clone(),
}
}
/// returns a new instance of the [`Rule`] with copied elements
pub fn copied(&self) -> Rule<Q, A>
where
Q: Clone,
A: Clone,
{
Rule {
head: self.head.clone(),
tail: self.tail.clone(),
}
}
}