Skip to main content

Rule

Struct Rule 

Source
#[repr(C)]
pub struct Rule<Q1 = String, A = char, Q2 = Q1, B = A>
where Q1: RawState, Q2: RawState,
{ pub head: Head<Q1, A>, pub tail: Tail<Q2, B>, }
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<Q1, A>§tail: Tail<Q2, B>

Implementations§

Source§

impl<Q, A, R, B> Rule<Q, A, R, B>
where Q: RawState, R: RawState,

Source

pub const fn new(head: Head<Q, A>, tail: Tail<R, B>) -> Self

returns a new instance of the Rule from the given head and tail

Source

pub const fn init() -> RuleBuilder<Q, A, R, B>

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: R, write_symbol: B, ) -> Self

initialize a new instance of the Rule from its consituent parts

Source

pub fn with_head(self, head: Head<Q, A>) -> Self

consumes the current object to create another with the given head

Source

pub fn with_tail(self, tail: Tail<R, B>) -> Self

consumes the current object to create another with the given tail

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<R, B>

returns an immutable reference to the Tail of the Rule

Source

pub const fn tail_mut(&mut self) -> &mut Tail<R, B>

returns a mutable reference to the Tail of the Rule

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<&R, &B>

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<R>

returns the next State of the system

Source

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

returns a mutable reference to the next State of the system

Source

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

returns the symbol which will be written by the Head

Source

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

returns a mutable reference to the next symbol

Source

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

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

Source

pub const fn write_symbol_mut(&mut self) -> &mut B

returns a mutable reference to the next symbol

Source

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

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

Source

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

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

Source

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

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

Source

pub fn set_next_state(&mut self, state: R)

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

Source

pub fn set_next_symbol(&mut self, symbol: B)

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

Source

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

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

Source

pub fn set_tail(&mut self, state: R, symbol: B)

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

Source

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

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

Source

pub const fn next_head(&self) -> Head<&R, &B>

returns the next Head of the system

Source

pub fn into_next_head(self) -> Head<R, B>

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

Source§

impl<Q, A, R, B> Rule<&Q, &A, &R, &B>
where Q: RawState, R: RawState,

Source

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

returns a new instance of the Rule with cloned elements

Source

pub const fn copied(&self) -> Rule<Q, A, R, B>
where Q: Copy, A: Copy, R: Copy, B: Copy,

returns a new instance of the Rule with copied elements

Source§

impl<Q, A> Rule<Q, usize, Q, A>
where Q: RawState,

Source

pub fn shift(&mut self, tape: &mut [A]) -> Option<Head<Q, A>>
where A: Clone, Q: Clone,

this method shifts the head along the tape, returning a head containing the previous state and symbol.

note: this method does not check if the current nor the next state is halted, it is up to the caller to establishing halting.

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<Q1, A: Clone, Q2, B: Clone> Clone for Rule<Q1, A, Q2, B>
where Q1: RawState + Clone, Q2: RawState + Clone,

Source§

fn clone(&self) -> Rule<Q1, A, Q2, B>

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<Q1, A: Debug, Q2, B: Debug> Debug for Rule<Q1, A, Q2, B>
where Q1: RawState + Debug, Q2: RawState + Debug,

Source§

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

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

impl<Q1, A: Default, Q2, B: Default> Default for Rule<Q1, A, Q2, B>
where Q1: RawState + Default, Q2: RawState + Default,

Source§

fn default() -> Rule<Q1, A, Q2, B>

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

impl<Q, A> Extend<Rule<Q, A>> for InstructionSet<Q, A>
where Q: RawState,

Source§

fn extend<I: IntoIterator<Item = Rule<Q, A>>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
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<Q1, A, Q2, B> From<RuleBuilder<Q1, A, Q2, B>> for Rule<Q1, A, Q2, B>
where Q1: RawState, Q2: RawState,

Source§

fn from(builder: RuleBuilder<Q1, A, Q2, B>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from_iter<I: IntoIterator<Item = Rule<Q, A>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<Q1, A: Hash, Q2, B: Hash> Hash for Rule<Q1, A, Q2, B>
where Q1: RawState + Hash, Q2: 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> Instruction<Q, A> for Rule<Q, A>
where Q: RawState,

Source§

type Head = Head<Q, A>

the type of head used by the instruction
Source§

type Tail = Tail<Q, A>

the type of tail used by the instruction
Source§

fn head(&self) -> &Self::Head

returns a reference to the head of the instruction
Source§

fn tail(&self) -> &Self::Tail

returns a reference to the tail of the instruction
Source§

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

returns a reference to the current state
Source§

fn symbol(&self) -> &A

returns a reference to the current symbol
Source§

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

returns a reference to the next state
Source§

fn next_symbol(&self) -> &A

returns a reference to the next symbol
Source§

fn direction(&self) -> Direction

returns the direction of the tail
Source§

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

Source§

fn head_mut(&mut self) -> &mut Self::Head

returns a mutable reference to the head of the instruction
Source§

fn tail_mut(&mut self) -> &mut Self::Tail

returns a mutable reference to the tail of the instruction
Source§

fn current_state_mut(&mut self) -> &mut State<Q>

returns a mutable reference to the current state
Source§

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

returns a mutable reference to the current symbol
Source§

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

returns a mutable reference to the next state
Source§

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

returns a mutable reference to the next symbol
Source§

impl<Q1, A: Ord, Q2, B: Ord> Ord for Rule<Q1, A, Q2, B>
where Q1: RawState + Ord, Q2: RawState + Ord,

Source§

fn cmp(&self, other: &Rule<Q1, A, Q2, B>) -> 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<Q1, A: PartialEq, Q2, B: PartialEq> PartialEq for Rule<Q1, A, Q2, B>
where Q1: RawState + PartialEq, Q2: RawState + PartialEq,

Source§

fn eq(&self, other: &Rule<Q1, A, Q2, B>) -> 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<Q1, A: PartialOrd, Q2, B: PartialOrd> PartialOrd for Rule<Q1, A, Q2, B>

Source§

fn partial_cmp(&self, other: &Rule<Q1, A, Q2, B>) -> 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<Q1, A: Copy, Q2, B: Copy> Copy for Rule<Q1, A, Q2, B>
where Q1: RawState + Copy, Q2: RawState + Copy,

Source§

impl<Q1, A: Eq, Q2, B: Eq> Eq for Rule<Q1, A, Q2, B>
where Q1: RawState + Eq, Q2: RawState + Eq,

Source§

impl<Q1, A, Q2, B> StructuralPartialEq for Rule<Q1, A, Q2, B>
where Q1: RawState, Q2: RawState,

Auto Trait Implementations§

§

impl<Q1, A, Q2, B> Freeze for Rule<Q1, A, Q2, B>
where A: Freeze, B: Freeze, Q1: Freeze, Q2: Freeze,

§

impl<Q1, A, Q2, B> RefUnwindSafe for Rule<Q1, A, Q2, B>

§

impl<Q1, A, Q2, B> Send for Rule<Q1, A, Q2, B>
where A: Send, B: Send, Q1: Send, Q2: Send,

§

impl<Q1, A, Q2, B> Sync for Rule<Q1, A, Q2, B>
where A: Sync, B: Sync, Q1: Sync, Q2: Sync,

§

impl<Q1, A, Q2, B> Unpin for Rule<Q1, A, Q2, B>
where A: Unpin, B: Unpin, Q1: Unpin, Q2: Unpin,

§

impl<Q1, A, Q2, B> UnwindSafe for Rule<Q1, A, Q2, B>
where A: UnwindSafe, B: UnwindSafe, Q1: UnwindSafe, Q2: 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<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<Q, A, T> IntoHead<Q, A> for T
where T: Into<Head<Q, A>>,

Source§

fn into_head(self) -> Head<Q, A>

Source§

impl<U, Q> IntoState<Q> for U
where Q: RawState, U: Into<State<Q>>,

Source§

fn __private__(&self) -> Seal

Source§

fn into_state(self) -> State<Q>

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> Wrapper<T> for T

Source§

type Cont<U> = U

Source§

fn get(&self) -> &T

returns a reference to the inner value
Source§

fn view(&self) -> <T as Wrapper<T>>::Cont<&T>

returns a view of the container containing an immutable reference to the inner value