#[repr(C)]pub struct Head<Q, S> {
pub state: State<Q>,
pub symbol: S,
}
Expand description
The Head is formally defined to be a 2-tuple consisting of a state / symbol pair.
Fields§
§state: State<Q>
§symbol: S
Implementations§
Source§impl<Q, S> Head<Q, S>where
Q: RawState,
impl<Q, S> Head<Q, S>where
Q: RawState,
pub const fn new(state: State<Q>, symbol: S) -> Self
Sourcepub fn from_state(state: State<Q>) -> Selfwhere
S: Default,
pub fn from_state(state: State<Q>) -> Selfwhere
S: Default,
Create a new instance of the Head using the given state and default symbol.
Sourcepub fn from_symbol(symbol: S) -> Selfwhere
Q: Default,
pub fn from_symbol(symbol: S) -> Selfwhere
Q: Default,
Create a new instance of the Head using the given symbol and default state.
Sourcepub fn from_tuple((state, symbol): (State<Q>, S)) -> Self
pub fn from_tuple((state, symbol): (State<Q>, S)) -> Self
Create a new instance from a 2-tuple: (state, symbol)
Sourcepub fn with_state(self, state: State<Q>) -> Self
pub fn with_state(self, state: State<Q>) -> Self
Updates the current state and returns a new head
Sourcepub fn with_symbol(self, symbol: S) -> Self
pub fn with_symbol(self, symbol: S) -> Self
Updates the current symbol and returns a new head
Sourcepub const fn state_mut(&mut self) -> &mut State<Q>
pub const fn state_mut(&mut self) -> &mut State<Q>
Returns a mutable reference to the current State
Sourcepub const fn symbol_mut(&mut self) -> &mut S
pub const fn symbol_mut(&mut self) -> &mut S
Returns a mutable reference to the current symbol
Sourcepub fn as_tuple(&self) -> (&State<Q>, &S)
pub fn as_tuple(&self) -> (&State<Q>, &S)
Returns a reference to the current state and symbol returing a 2-tuple
Sourcepub fn into_tuple(self) -> (State<Q>, S)
pub fn into_tuple(self) -> (State<Q>, S)
Consumes the head and returns the current state and symbol as a 2-tuple
Sourcepub fn as_mut_tuple(&mut self) -> (&mut State<Q>, &mut S)
pub fn as_mut_tuple(&mut self) -> (&mut State<Q>, &mut S)
Returns a mutable reference to the current state and symbol as a 2-tuple
Sourcepub fn set_symbol(&mut self, symbol: S) -> &mut Self
pub fn set_symbol(&mut self, symbol: S) -> &mut Self
Updates the current symbol
Sourcepub fn replace(&mut self, state: State<Q>, symbol: S) -> Self
pub fn replace(&mut self, state: State<Q>, symbol: S) -> Self
Replaces the current state and symbol with the given state and symbol; returns the previous instance of the head.
Sourcepub const fn replace_state(&mut self, state: State<Q>) -> State<Q>
pub const fn replace_state(&mut self, state: State<Q>) -> State<Q>
replace
the current state with the given state, returning the
previous state
Sourcepub const fn replace_symbol(&mut self, symbol: S) -> S
pub const fn replace_symbol(&mut self, symbol: S) -> S
replace
the current symbol with the given symbol, returning the
previous symbol
Sourcepub const fn swap(&mut self, other: &mut Self)
pub const fn swap(&mut self, other: &mut Self)
swap
the current state and symbol with those of the given head
Sourcepub fn update(&mut self, state: Option<State<Q>>, symbol: Option<S>)
pub fn update(&mut self, state: Option<State<Q>>, symbol: Option<S>)
Updates the current State and symbol
Sourcepub const fn view(&self) -> Head<&Q, &S>
pub const fn view(&self) -> Head<&Q, &S>
returns a new head with immutable references to the current state and symbol
Sourcepub fn view_mut(&mut self) -> Head<&mut Q, &mut S>
pub fn view_mut(&mut self) -> Head<&mut Q, &mut S>
returns a new head with mutable references to the current state and symbol
Sourcepub fn read<T>(self, tape: &[T]) -> Option<&S::Output>where
S: SliceIndex<[T]>,
pub fn read<T>(self, tape: &[T]) -> Option<&S::Output>where
S: SliceIndex<[T]>,
tries reading the given tape using the head as its coordinates.
pub fn to_ref(&self) -> Head<&Q, &S>
view
instead, as it is more idiomatic and clearer.pub fn to_mut(&mut self) -> Head<&mut Q, &mut S>
view_mut
instead, as it is more idiomatic and clearer.