1mod impl_head;
6mod impl_head_ext;
7mod impl_head_repr;
8
9#[allow(deprecated)]
10mod impl_deprecated;
11
12use rstm_state::{RawState, State};
13
14pub type HeadRef<'a, Q, S> = Head<&'a Q, &'a S>;
16pub type HeadMut<'a, Q, S> = Head<&'a mut Q, &'a mut S>;
18
19pub trait AsHead<Q, A>
21where
22 Q: RawState,
23{
24 fn as_head(&self) -> Head<Q, A>;
25}
26pub trait IntoHead<Q, A>
28where
29 Q: RawState,
30{
31 fn into_head(self) -> Head<Q, A>;
32}
33
34#[derive(Clone, Copy, Default, PartialEq, Eq, Hash, Ord, PartialOrd)]
38#[cfg_attr(
39 feature = "serde",
40 derive(serde::Deserialize, serde::Serialize),
41 serde(rename_all = "camelCase")
42)]
43#[repr(C)]
44pub struct Head<Q, S> {
45 #[cfg_attr(feature = "serde", serde(alias = "currentState"))]
46 pub state: State<Q>,
47 #[cfg_attr(feature = "serde", serde(alias = "currentSymbol"))]
48 pub symbol: S,
49}
50
51impl<Q, A, T> IntoHead<Q, A> for T
56where
57 Q: RawState,
58 T: Into<Head<Q, A>>,
59{
60 fn into_head(self) -> Head<Q, A> {
61 self.into()
62 }
63}
64
65impl<Q, S> From<(Q, S)> for Head<Q, S>
66where
67 Q: RawState,
68{
69 fn from((state, symbol): (Q, S)) -> Self {
70 Self::new(state, symbol)
71 }
72}
73
74impl<Q, S> From<(State<Q>, S)> for Head<Q, S>
75where
76 Q: RawState,
77{
78 fn from((state, symbol): (State<Q>, S)) -> Self {
79 Head { state, symbol }
80 }
81}
82
83impl<Q, S> From<Head<Q, S>> for (State<Q>, S)
84where
85 Q: RawState,
86{
87 fn from(Head { state, symbol }: Head<Q, S>) -> Self {
88 (state, symbol)
89 }
90}