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
pub use self::{head::*, moves::*, tail::*};
pub(crate) mod head;
pub(crate) mod moves;
pub(crate) mod tail;
use crate::{
states::{State, States},
turing::Symbolic,
};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct Instruction<S: Symbolic>(Head<S>, Tail<S>);
impl<S: Symbolic> Instruction<S> {
pub fn new(head: Head<S>, tail: Tail<S>) -> Self {
Self(head, tail)
}
pub fn head(&self) -> &Head<S> {
&self.0
}
pub fn tail(&self) -> &Tail<S> {
&self.1
}
pub fn update(&mut self, head: Head<S>, tail: Tail<S>) {
self.0 = head;
self.1 = tail;
}
}
impl<S: Symbolic> From<(State<States>, S, State<States>, S, Move)> for Instruction<S> {
fn from(value: (State<States>, S, State<States>, S, Move)) -> Self {
let head = Head::new(value.0, value.1);
let tail = Tail::new(value.2, value.3, value.4);
Self::new(head, tail)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::states::States;
#[test]
fn test_instructions() {
let head = Head::new(State::new(States::invalid()), "b");
let tail = Tail::new(State::new(States::invalid()), "a", Move::Right);
let instructions = Instruction::new(head, tail);
assert_eq!(instructions.tail().action(), &Move::Right)
}
}