Rule

Struct Rule 

Source
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,

Source

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

Source

pub const fn create() -> RuleBuilder<Q, A>

returns a new instance of a RuleBuilder for constructing a new Rule

Source

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

Source

pub const fn head(&self) -> &Head<Q, A>

returns an immutable reference to the Head

Source

pub const fn head_mut(&mut self) -> &mut Head<Q, A>

returns a mutable reference to the Head

Source

pub const fn tail(&self) -> &Tail<Q, A>

returns an immutable reference to the Tail of the [Instruction]

Source

pub const fn tail_mut(&mut self) -> &mut Tail<Q, A>

returns a mutable reference to the Tail of the [Instruction]

Source

pub const fn head_view(&self) -> Head<&Q, &A>

returns an instance of the Head whose elements are immutable references

Source

pub const fn tail_view(&self) -> Tail<&Q, &A>

returns an instance of the Tail whose elements are immutable references

Source

pub const fn direction(&self) -> Direction

returns the direction of the shift

Source

pub const fn state(&self) -> &State<Q>

returns the current State of the system

Source

pub const fn state_mut(&mut self) -> &mut State<Q>

returns a mutable reference to the current State of the system

Source

pub const fn symbol(&self) -> &A

returns the symbol of the Head

Source

pub const fn symbol_mut(&mut self) -> &mut A

returns a mutable reference to the symbol of the Head

Source

pub const fn next_state(&self) -> &State<Q>

returns the next State of the system

Source

pub const fn next_state_mut(&mut self) -> &mut State<Q>

returns a mutable reference to the next State of the system

Source

pub const fn next_symbol(&self) -> &A

returns the symbol which will be written by the Head

Source

pub const fn next_symbol_mut(&mut self) -> &mut A

returns a mutable reference to the next symbol

Source

pub fn set_direction(&mut self, direction: Direction) -> &mut Self

updates the current Direction and returns a mutable reference to the Rule

Source

pub fn set_symbol(&mut self, symbol: A) -> &mut Self

update the current symbol and return a mutable reference to the Rule

Source

pub fn set_state(&mut self, state: Q) -> &mut Self

updates the current State and returns a mutable reference to the Rule

Source

pub fn set_next_state(&mut self, state: Q) -> &mut Self

updates the current State and returns a mutable reference to the Rule

Source

pub fn set_next_symbol(&mut self, symbol: A) -> &mut Self

updates the next symbol and returns a mutable reference to the Rule

Source

pub fn set_head(&mut self, state: Q, symbol: A) -> &mut Self

updates the current State and symbol and returns a mutable reference to the Rule

Source

pub fn set_tail(&mut self, state: Q, symbol: A) -> &mut Self

updates the current State and symbol and returns a mutable reference to the Rule

Source

pub const fn next_head(&self) -> Head<&Q, &A>

returns the next Head of the system

Source

pub fn into_next_head(self) -> Head<Q, A>

consumes the current object and returns the next Head of the system

Source

pub const fn write_symbol(&self) -> &A

returns the value which for which the current object will be replaced with

Source

pub fn into_tuple(self) -> (Head<Q, A>, Tail<Q, A>)

consumes the current object and returns a 2-tuple consisting of the Head and Tail

Source

pub fn cloned(&self) -> Rule<Q, A>
where Q: Clone, A: Clone,

returns a new instance of the Rule with cloned elements

Source

pub fn copied(&self) -> Rule<Q, A>
where Q: Clone, A: Clone,

returns a new instance of the Rule with copied elements

Trait Implementations§

Source§

impl<Q, S> AsMut<Head<Q, S>> for Rule<Q, S>
where Q: RawState,

Source§

fn as_mut(&mut self) -> &mut Head<Q, S>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<Q, S> AsMut<Tail<Q, S>> for Rule<Q, S>
where Q: RawState,

Source§

fn as_mut(&mut self) -> &mut Tail<Q, S>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<Q, S> AsRef<Head<Q, S>> for Rule<Q, S>
where Q: RawState,

Source§

fn as_ref(&self) -> &Head<Q, S>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<Q, S> AsRef<Tail<Q, S>> for Rule<Q, S>
where Q: RawState,

Source§

fn as_ref(&self) -> &Tail<Q, S>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<Q, S> Borrow<Head<Q, S>> for Rule<Q, S>
where Q: RawState,

Source§

fn borrow(&self) -> &Head<Q, S>

Immutably borrows from an owned value. Read more
Source§

impl<Q, S> Borrow<Tail<Q, S>> for Rule<Q, S>
where Q: RawState,

Source§

fn borrow(&self) -> &Tail<Q, S>

Immutably borrows from an owned value. Read more
Source§

impl<Q, S> BorrowMut<Head<Q, S>> for Rule<Q, S>
where Q: RawState,

Source§

fn borrow_mut(&mut self) -> &mut Head<Q, S>

Mutably borrows from an owned value. Read more
Source§

impl<Q, S> BorrowMut<Tail<Q, S>> for Rule<Q, S>
where Q: RawState,

Source§

fn borrow_mut(&mut self) -> &mut Tail<Q, S>

Mutably borrows from an owned value. Read more
Source§

impl<Q, A: Clone> Clone for Rule<Q, A>
where Q: RawState + Clone,

Source§

fn clone(&self) -> Rule<Q, A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Q, A: Debug> Debug for Rule<Q, A>
where Q: RawState + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Q, A: Default> Default for Rule<Q, A>
where Q: RawState + Default,

Source§

fn default() -> Rule<Q, A>

Returns the “default value” for a type. Read more
Source§

impl<'de, Q, A> Deserialize<'de> for Rule<Q, A>
where Q: RawState + Deserialize<'de>, A: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Q, S> Directive<Q, S> for Rule<Q, S>
where Q: RawState,

Source§

impl<Q, S> From<(Head<Q, S>, Tail<Q, S>)> for Rule<Q, S>
where Q: RawState,

Source§

fn from((head, tail): (Head<Q, S>, Tail<Q, S>)) -> Self

Converts to this type from the input type.
Source§

impl<Q, S> From<Rule<Q, S>> for (Head<Q, S>, Tail<Q, S>)
where Q: RawState,

Source§

fn from(rule: Rule<Q, S>) -> Self

Converts to this type from the input type.
Source§

impl<Q, S, T> From<Rule<Q, S>> for LearnedRule<T, Q, S>
where Q: RawState, T: Default,

Source§

fn from(rule: Rule<Q, S>) -> Self

Converts to this type from the input type.
Source§

impl<Q, S> From<RuleBuilder<Q, S>> for Rule<Q, S>
where Q: RawState,

Source§

fn from(builder: RuleBuilder<Q, S>) -> Self

Converts to this type from the input type.
Source§

impl<Q, A: Hash> Hash for Rule<Q, A>
where Q: RawState + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<Q, A: Ord> Ord for Rule<Q, A>
where Q: RawState + Ord,

Source§

fn cmp(&self, other: &Rule<Q, A>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<Q, S> PartialEq<(Head<Q, S>, Tail<Q, S>)> for Rule<Q, S>
where Q: RawState + PartialEq, S: PartialEq,

Source§

fn eq(&self, other: &(Head<Q, S>, Tail<Q, S>)) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Q, S> PartialEq<Head<Q, S>> for Rule<Q, S>
where Q: RawState + PartialEq, S: PartialEq,

Source§

fn eq(&self, other: &Head<Q, S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Q, S> PartialEq<Tail<Q, S>> for Rule<Q, S>
where Q: RawState + PartialEq, S: PartialEq,

Source§

fn eq(&self, other: &Tail<Q, S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Q, A: PartialEq> PartialEq for Rule<Q, A>
where Q: RawState + PartialEq,

Source§

fn eq(&self, other: &Rule<Q, A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Q, A: PartialOrd> PartialOrd for Rule<Q, A>
where Q: RawState + PartialOrd,

Source§

fn partial_cmp(&self, other: &Rule<Q, A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Q, S> Scope<Q, S> for Rule<Q, S>
where Q: RawState,

Source§

fn current_state(&self) -> &State<Q>

returns an immutable reference to the current state
Source§

fn current_symbol(&self) -> &S

Source§

impl<Q, A> Serialize for Rule<Q, A>
where Q: RawState + Serialize, A: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Q, A: Copy> Copy for Rule<Q, A>
where Q: RawState + Copy,

Source§

impl<Q, A: Eq> Eq for Rule<Q, A>
where Q: RawState + Eq,

Source§

impl<Q, A> StructuralPartialEq for Rule<Q, A>
where Q: RawState,

Auto Trait Implementations§

§

impl<Q, A> Freeze for Rule<Q, A>
where A: Freeze, Q: Freeze,

§

impl<Q, A> RefUnwindSafe for Rule<Q, A>

§

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>
where A: Unpin, Q: Unpin,

§

impl<Q, A> UnwindSafe for Rule<Q, A>
where A: UnwindSafe, Q: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, Q, S> Instruction<Q, S> for A
where A: Scope<Q, S> + Directive<Q, S>, Q: RawState, S: Symbol,

Source§

fn direction(&self) -> Direction

returns a copy of the direction of the head
Source§

fn current_state(&self) -> &State<Q>

returns a reference to the current state of the Turing machine
Source§

fn next_state(&self) -> &State<Q>

returns a reference to the next state of the Turing machine
Source§

fn symbol(&self) -> &S

returns a reference to the current symbol under the head
Source§

fn write_symbol(&self) -> &S

returns a reference to the symbol to be written by the head
Source§

fn head(&self) -> Head<&Q, &S>

returns an instance of Head containing references to the current state and symbol
Source§

fn tail(&self) -> Tail<&Q, &S>

returns an instance of Tail containing references to the next state and symbol
Source§

fn as_rule(&self) -> Rule<&Q, &S>

returns an instance of Rule containing references to the states and symbols within
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,