rstm_core/head/
impl_head_repr.rs

1/*
2    Appellation: impl_head_repr <module>
3    Created At: 2025.08.31:00:01:56
4    Contrib: @FL03
5*/
6use super::{Head, HeadMut, HeadRef};
7use crate::types::Direction;
8use rstm_state::RawState;
9
10impl<'a, Q, S> HeadRef<'a, Q, S>
11where
12    Q: RawState,
13{
14    /// returns a new [`Head`] with cloned elements
15    pub fn cloned(&self) -> Head<Q, S>
16    where
17        Q: Clone,
18        S: Clone,
19    {
20        Head {
21            state: self.state.cloned(),
22            symbol: self.symbol.clone(),
23        }
24    }
25    /// returns a new [`Head`] with copied elements
26    pub fn copied(&self) -> Head<Q, S>
27    where
28        Q: Copy,
29        S: Copy,
30    {
31        Head {
32            state: self.state.copied(),
33            symbol: *self.symbol,
34        }
35    }
36}
37
38impl<'a, Q, S> HeadMut<'a, Q, S>
39where
40    Q: RawState,
41{
42    /// returns a new [`Head`] with cloned elements
43    pub fn cloned(&self) -> Head<Q, S>
44    where
45        Q: Clone,
46        S: Clone,
47    {
48        Head {
49            state: self.state.cloned(),
50            symbol: self.symbol.clone(),
51        }
52    }
53    /// returns a new [`Head`] with copied elements
54    pub fn copied(&self) -> Head<Q, S>
55    where
56        Q: Copy,
57        S: Copy,
58    {
59        Head {
60            state: self.state.copied(),
61            symbol: *self.symbol,
62        }
63    }
64}
65
66impl<Q> Head<Q, usize>
67where
68    Q: RawState,
69{
70    pub fn shift(self, direction: Direction) -> Self {
71        Self {
72            symbol: direction.apply_unsigned(self.symbol),
73            ..self
74        }
75    }
76
77    pub fn shift_inplace(&mut self, direction: Direction) {
78        self.symbol = direction.apply_unsigned(self.symbol);
79    }
80}