turing_machine_rs/instruction/
tail.rs

1use std::fmt::{Display, Error, Formatter};
2
3use crate::instruction::{Move, State};
4use crate::Symbol;
5
6/// Tail is the second part of [`crate::instruction::Instruction`]
7/// and is used as a container for the [`State`], the [`Symbol`], and the [`Move`].
8///
9/// [`Tail`] fields doesn't needs in control or protection so they are public.
10#[derive(Clone, Debug, PartialEq, Eq)]
11pub struct Tail<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    /// [`Move`] enum variant ([`Move::Left`], [`Move::Right`], [`Move::None`])
18    /// which is used by [`crate::state::Configuration`].
19    pub movement: Move,
20}
21
22impl<S: Symbol> Tail<S> {
23    /// Constructs a new [`Tail`] with the [`State`], the [`Symbol`] and the [`Move`].
24    #[rustfmt::skip]
25    pub fn new(state: State, symbol: S, movement: Move) -> Self {
26        Tail { state, symbol, movement }
27    }
28}
29
30impl<S: Symbol> Display for Tail<S> {
31    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
32        write!(f, "{}, {}, {}", self.state, self.symbol, self.movement)
33    }
34}