pub struct Rule<Q = String, A = char>where
Q: RawState,{
pub head: Head<Q, A>,
pub tail: Tail<Q, A>,
}Expand description
The Rule implementation is a concrete representation of a single instruction, or rule,
within a given Turing machine program. It encapsulates the necessary components to define
the behavior of the Turing machine when it encounters a specific state and symbol.
Note: The inner fields are flattened for serialization purposes when using serde;
this means that the fields of the Head and Tail structs will be serialized as if they
were direct fields of the Rule struct itself.
Fields§
§head: Head<Q, A>§tail: Tail<Q, A>Implementations§
Source§impl<Q, A> Rule<Q, A>where
Q: RawState,
impl<Q, A> Rule<Q, A>where
Q: RawState,
Sourcepub const fn new(head: Head<Q, A>, tail: Tail<Q, A>) -> Self
pub const fn new(head: Head<Q, A>, tail: Tail<Q, A>) -> Self
returns a new instance of the Rule from the given head and tail
Sourcepub const fn create() -> RuleBuilder<Q, A>
pub const fn create() -> RuleBuilder<Q, A>
returns a new instance of a RuleBuilder for constructing a new Rule
Sourcepub const fn from_parts(
state: Q,
symbol: A,
direction: Direction,
next_state: Q,
write_symbol: A,
) -> Self
pub const fn from_parts( state: Q, symbol: A, direction: Direction, next_state: Q, write_symbol: A, ) -> Self
initialize a new instance of the Rule from its consituent parts
Sourcepub const fn tail(&self) -> &Tail<Q, A>
pub const fn tail(&self) -> &Tail<Q, A>
returns an immutable reference to the Tail of the [Instruction]
Sourcepub const fn tail_mut(&mut self) -> &mut Tail<Q, A>
pub const fn tail_mut(&mut self) -> &mut Tail<Q, A>
returns a mutable reference to the Tail of the [Instruction]
Sourcepub const fn head_view(&self) -> Head<&Q, &A>
pub const fn head_view(&self) -> Head<&Q, &A>
returns an instance of the Head whose elements are immutable references
Sourcepub const fn tail_view(&self) -> Tail<&Q, &A>
pub const fn tail_view(&self) -> Tail<&Q, &A>
returns an instance of the Tail whose elements are immutable references
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 of the system
Sourcepub const fn symbol_mut(&mut self) -> &mut A
pub const fn symbol_mut(&mut self) -> &mut A
returns a mutable reference to the symbol of the Head
Sourcepub const fn next_state(&self) -> &State<Q>
pub const fn next_state(&self) -> &State<Q>
returns the next State of the system
Sourcepub const fn next_state_mut(&mut self) -> &mut State<Q>
pub const fn next_state_mut(&mut self) -> &mut State<Q>
returns a mutable reference to the next State of the system
Sourcepub const fn next_symbol(&self) -> &A
pub const fn next_symbol(&self) -> &A
returns the symbol which will be written by the Head
Sourcepub const fn next_symbol_mut(&mut self) -> &mut A
pub const fn next_symbol_mut(&mut self) -> &mut A
returns a mutable reference to the next symbol
Sourcepub fn set_direction(&mut self, direction: Direction) -> &mut Self
pub fn set_direction(&mut self, direction: Direction) -> &mut Self
Sourcepub fn set_symbol(&mut self, symbol: A) -> &mut Self
pub fn set_symbol(&mut self, symbol: A) -> &mut Self
update the current symbol and return a mutable reference to the Rule
Sourcepub fn set_next_state(&mut self, state: Q) -> &mut Self
pub fn set_next_state(&mut self, state: Q) -> &mut Self
Sourcepub fn set_next_symbol(&mut self, symbol: A) -> &mut Self
pub fn set_next_symbol(&mut self, symbol: A) -> &mut Self
updates the next symbol and returns a mutable reference to the Rule
Sourcepub fn into_next_head(self) -> Head<Q, A>
pub fn into_next_head(self) -> Head<Q, A>
consumes the current object and returns the next Head of the system
Sourcepub const fn write_symbol(&self) -> &A
pub const fn write_symbol(&self) -> &A
returns the value which for which the current object will be replaced with
Sourcepub fn into_tuple(self) -> (Head<Q, A>, Tail<Q, A>)
pub fn into_tuple(self) -> (Head<Q, A>, Tail<Q, A>)
Trait Implementations§
Source§impl<Q, S> BorrowMut<Head<Q, S>> for Rule<Q, S>where
Q: RawState,
impl<Q, S> BorrowMut<Head<Q, S>> for Rule<Q, S>where
Q: RawState,
Source§fn borrow_mut(&mut self) -> &mut Head<Q, S>
fn borrow_mut(&mut self) -> &mut Head<Q, S>
Source§impl<Q, S> BorrowMut<Tail<Q, S>> for Rule<Q, S>where
Q: RawState,
impl<Q, S> BorrowMut<Tail<Q, S>> for Rule<Q, S>where
Q: RawState,
Source§fn borrow_mut(&mut self) -> &mut Tail<Q, S>
fn borrow_mut(&mut self) -> &mut Tail<Q, S>
Source§impl<'de, Q, A> Deserialize<'de> for Rule<Q, A>
impl<'de, Q, A> Deserialize<'de> for Rule<Q, A>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<Q, S, T> From<Rule<Q, S>> for LearnedRule<T, Q, S>
impl<Q, S, T> From<Rule<Q, S>> for LearnedRule<T, Q, S>
Source§impl<Q, S> From<RuleBuilder<Q, S>> for Rule<Q, S>where
Q: RawState,
impl<Q, S> From<RuleBuilder<Q, S>> for Rule<Q, S>where
Q: RawState,
Source§fn from(builder: RuleBuilder<Q, S>) -> Self
fn from(builder: RuleBuilder<Q, S>) -> Self
Source§impl<Q, A: Ord> Ord for Rule<Q, A>
impl<Q, A: Ord> Ord for Rule<Q, A>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<Q, A: PartialOrd> PartialOrd for Rule<Q, A>where
Q: RawState + PartialOrd,
impl<Q, A: PartialOrd> PartialOrd for Rule<Q, A>where
Q: RawState + PartialOrd,
Source§impl<Q, S> Scope<Q, S> for Rule<Q, S>where
Q: RawState,
impl<Q, S> Scope<Q, S> for Rule<Q, S>where
Q: RawState,
Source§fn current_state(&self) -> &State<Q>
fn current_state(&self) -> &State<Q>
fn current_symbol(&self) -> &S
impl<Q, A: Copy> Copy for Rule<Q, A>
impl<Q, A: Eq> Eq for Rule<Q, A>
impl<Q, A> StructuralPartialEq for Rule<Q, A>where
Q: RawState,
Auto Trait Implementations§
impl<Q, A> Freeze for Rule<Q, A>
impl<Q, A> RefUnwindSafe for Rule<Q, A>where
A: RefUnwindSafe,
Q: RefUnwindSafe,
impl<Q, A> Send for Rule<Q, A>where
A: Send,
impl<Q, A> Sync for Rule<Q, A>where
A: Sync,
impl<Q, A> Unpin for Rule<Q, A>
impl<Q, A> UnwindSafe for Rule<Q, A>where
A: UnwindSafe,
Q: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<A, Q, S> Instruction<Q, S> for A
impl<A, Q, S> Instruction<Q, S> for A
Source§fn current_state(&self) -> &State<Q>
fn current_state(&self) -> &State<Q>
Source§fn next_state(&self) -> &State<Q>
fn next_state(&self) -> &State<Q>
Source§fn write_symbol(&self) -> &S
fn write_symbol(&self) -> &S
Source§fn head(&self) -> Head<&Q, &S>
fn head(&self) -> Head<&Q, &S>
Head containing references to the current state and symbol