turing_machine_rs/instruction/head.rs
1use crate::instruction::State;
2use crate::Symbol;
3
4use std::fmt::{Display, Error, Formatter};
5
6/// [`Head`] is the first part of [`crate::instruction::Instruction`]
7/// and is used as a container for the [`State`] and the [`Symbol`].
8///
9/// [`Head`] fields doesn't needs in control or protection so they are public.
10#[derive(Clone, Debug, PartialEq, Eq)]
11pub struct Head<S: Symbol> {
12 /// [`State`] which is a wrapper around usize.
13 /// It's very hard (impossible) to reach the limit manually.
14 pub state: State,
15 /// Any struct or object which implements [`Symbol`] trait.
16 pub symbol: S,
17}
18
19impl<S: Symbol> Head<S> {
20 /// Constructs a new [`Head`] with the [`State`] and the [`Symbol`].
21 pub fn new(state: State, symbol: S) -> Self {
22 Head { state, symbol }
23 }
24}
25
26impl<S: Symbol> Display for Head<S> {
27 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
28 write!(f, "{}, {}", self.state, self.symbol)
29 }
30}