rstm_rules/rule/
impl_rule.rs1use super::{Rule, RuleBuilder};
6
7use rstm_core::{Direction, Head, Tail};
8use rstm_state::{RawState, State};
9
10impl<Q, A> Rule<Q, A>
11where
12 Q: RawState,
13{
14 pub const fn new() -> RuleBuilder<Q, A> {
15 RuleBuilder::new()
16 }
17 pub const fn head(&self) -> &Head<Q, A> {
19 &self.head
20 }
21 pub const fn head_mut(&mut self) -> &mut Head<Q, A> {
23 &mut self.head
24 }
25 pub const fn tail(&self) -> &Tail<Q, A> {
27 &self.tail
28 }
29 pub const fn tail_mut(&mut self) -> &mut Tail<Q, A> {
31 &mut self.tail
32 }
33 pub const fn head_view(&self) -> Head<&'_ Q, &'_ A> {
35 self.head().view()
36 }
37 pub const fn tail_view(&self) -> Tail<&'_ Q, &'_ A> {
39 self.tail().view()
40 }
41 pub const fn direction(&self) -> Direction {
43 self.tail().direction()
44 }
45 pub const fn state(&self) -> &State<Q> {
47 self.head().state()
48 }
49 pub const fn state_mut(&mut self) -> &mut State<Q> {
51 self.head_mut().state_mut()
52 }
53 pub const fn symbol(&self) -> &A {
55 self.head().symbol()
56 }
57 pub const fn symbol_mut(&mut self) -> &mut A {
59 self.head_mut().symbol_mut()
60 }
61 pub const fn next_state(&self) -> &State<Q> {
63 self.tail().state()
64 }
65 pub const fn next_state_mut(&mut self) -> &mut State<Q> {
67 self.tail_mut().state_mut()
68 }
69 pub const fn next_symbol(&self) -> &A {
71 self.tail().symbol()
72 }
73 pub const fn next_symbol_mut(&mut self) -> &mut A {
75 self.tail_mut().symbol_mut()
76 }
77 pub fn set_direction(&mut self, direction: Direction) -> &mut Self {
79 self.tail_mut().set_direction(direction);
80 self
81 }
82 pub fn set_symbol(&mut self, symbol: A) -> &mut Self {
84 self.head_mut().set_symbol(symbol);
85 self
86 }
87 pub fn set_state(&mut self, state: Q) -> &mut Self {
89 self.head_mut().set_state(state);
90 self
91 }
92 pub fn set_next_state(&mut self, state: Q) -> &mut Self {
94 self.tail_mut().set_state(state);
95 self
96 }
97 pub fn set_next_symbol(&mut self, symbol: A) -> &mut Self {
99 self.tail_mut().set_symbol(symbol);
100 self
101 }
102 pub fn set_head(&mut self, state: Q, symbol: A) -> &mut Self {
104 self.head_mut().set_state(state);
105 self.head_mut().set_symbol(symbol);
106 self
107 }
108 pub fn set_tail(&mut self, state: Q, symbol: A) -> &mut Self {
110 self.tail_mut().set_state(state);
111 self.tail_mut().set_symbol(symbol);
112 self
113 }
114 pub const fn next_head(&self) -> Head<&'_ Q, &'_ A> {
116 self.tail().as_head()
117 }
118 pub fn into_next_head(self) -> Head<Q, A> {
120 self.tail.into_head()
121 }
122 pub const fn write_symbol(&self) -> &A {
124 self.tail().symbol()
125 }
126 pub fn into_tuple(self) -> (Head<Q, A>, Tail<Q, A>) {
128 (self.head, self.tail)
129 }
130 pub fn cloned(&self) -> Rule<Q, A>
132 where
133 Q: Clone,
134 A: Clone,
135 {
136 Rule {
137 head: self.head.clone(),
138 tail: self.tail.clone(),
139 }
140 }
141 pub fn copied(&self) -> Rule<Q, A>
143 where
144 Q: Clone,
145 A: Clone,
146 {
147 Rule {
148 head: self.head.clone(),
149 tail: self.tail.clone(),
150 }
151 }
152}