Skip to main content

Head

Struct Head 

Source
#[repr(C)]
pub struct Head<Q, A> { pub state: State<Q>, pub symbol: A, }
Expand description

The Head of a Turing machine is defined to be a two-tuple consisting of a state and a symbol. Our implementation is generic over both the state and symbol types, allowing for flexibility in their representation(s).

Fields§

§state: State<Q>§symbol: A

Implementations§

Source§

impl<Q, A> Head<Q, A>
where Q: RawState,

The core implementation of the Head providing fundamental methods for its manipulation, including various constructors, accessors, and mutators as well as convienience methods for converting between representations.

Source

pub const fn new(state: Q, symbol: A) -> Head<Q, A>

initialize a new instance of the Head given some state and symbol

Source

pub fn from_state(state: Q) -> Head<Q, A>
where A: Default,

returns a new instance of the head using the given state and a default symbol

Source

pub fn from_symbol(symbol: A) -> Head<Q, A>
where Q: Default,

returns a new instance of the head using the given symbol and a default state

Source

pub fn from_tail(_: Tail<Q, A>) -> Head<Q, A>

create an instance of the Head from a given Tail

Source

pub fn from_tuple(_: (State<Q>, A)) -> Head<Q, A>

Create a new instance from a 2-tuple: (state, symbol)

Source

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

returns a reference to the current state

Source

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

returns a mutable reference to the current State

Source

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

returns a reference to the current symbol

Source

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

returns a mutable reference to the current symbol

Source

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

updates the current state

Source

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

updates the current symbol

Source

pub fn with_state<Q2>(self, state: Q2) -> Head<Q2, A>

consumes the current instance to create another instance with the given state

Source

pub fn with_symbol<A2>(self, symbol: A2) -> Head<Q, A2>

consumes the current instance to create another instance with the given symbol

Source

pub const fn replace(&mut self, state: State<Q>, symbol: A) -> Head<Q, A>

replaces the current values with the given state and symbol, returning the previous instance of the Head

Source

pub const fn replace_state(&mut self, state: State<Q>) -> State<Q>

replace the current state with the given state, returning the previous state

Source

pub const fn replace_symbol(&mut self, symbol: A) -> A

replace the current symbol with the given symbol, returning the previous symbol

Source

pub const fn swap(&mut self, other: &mut Head<Q, A>)

swap the state and symbol of the current instance with another

Source

pub const fn swap_state(&mut self, other: &mut State<Q>)

swap the current state with another

Source

pub const fn swap_symbol(&mut self, other: &mut A)

swap the current symbol with another

Source

pub fn update(&mut self, state: Option<State<Q>>, symbol: Option<A>)

updates the current State and symbol

Source

pub const fn as_tuple(&self) -> (&State<Q>, &A)

returns a reference to the current state and symbol returing a 2-tuple

Source

pub const fn as_mut_tuple(&mut self) -> (&mut State<Q>, &mut A)

returns a mutable reference to the current state and symbol as a 2-tuple

Source

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

Consumes the head and returns the current state and symbol as a 2-tuple

Source

pub fn into_rule_with_tail(self, tail: Tail<Q, A>) -> Rule<Q, A>
where Q: RawState,

associates the given tail with the current head, returning a new Rule

Source

pub fn read_tape<T>(self, tape: &[T]) -> Option<&<A as SliceIndex<[T]>>::Output>
where A: SliceIndex<[T]>,

tries reading the given tape using the head as its coordinates.

Source

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

returns a new head with immutable references to the current state and symbol

Source

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

returns a new head with mutable references to the current state and symbol

Source

pub fn step<'a, Q2, B>( &'a mut self, tail: Tail<Q2, B>, ) -> HeadStep<'a, Q, A, Q2, B>
where Q2: RawState,

use the given Tail to initialize a new HeadStep instance for performing a step operation.

Note: this method is lazy, meaning that the actual step is not performed until an actionable method is called on the returned HeadStep instance.

Source§

impl<'a, Q, S> Head<&'a Q, &'a S>
where Q: RawState,

Source

pub fn cloned(&self) -> Head<Q, S>
where Q: Clone, S: Clone,

returns a new Head with cloned elements

Source

pub const fn copied(&self) -> Head<Q, S>
where Q: Copy, S: Copy,

returns a new Head with copied elements

Source§

impl<'a, Q, S> Head<&'a mut Q, &'a mut S>
where Q: RawState,

Source

pub fn cloned(&self) -> Head<Q, S>
where Q: Clone, S: Clone,

returns a new Head with cloned elements

Source

pub fn copied(&self) -> Head<Q, S>
where Q: Copy, S: Copy,

returns a new Head with copied elements

Source§

impl<Q> Head<Q, usize>
where Q: RawState,

Source

pub fn load<A>( self, program: ProgramBase<Vec<Rule<Q, A>>, Q, A>, ) -> EngineBase<Head<Q, usize>, Q, A>
where Q: PartialEq, A: PartialEq,

load the head into an engine loaded with the given program

Source

pub fn shift(self, direction: Direction) -> Head<Q, usize>

Source

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

Trait Implementations§

Source§

impl<Q, A, R, B> Add<Head<Q, A>> for Tail<R, B>
where Q: RawState, R: RawState,

Source§

type Output = Rule<Q, A, R, B>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Head<Q, A>) -> <Tail<R, B> as Add<Head<Q, A>>>::Output

Performs the + operation. Read more
Source§

impl<Q, A, R, B> Add<Tail<R, B>> for Head<Q, A>
where Q: RawState, R: RawState,

Source§

type Output = Rule<Q, A, R, B>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Tail<R, B>) -> <Head<Q, A> as Add<Tail<R, B>>>::Output

Performs the + operation. Read more
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> 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> 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, A> Borrow<State<Q>> for Head<Q, A>
where Q: RawState,

Source§

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

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, A> BorrowMut<State<Q>> for Head<Q, A>
where Q: RawState,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<Q, A> Clone for Head<Q, A>
where Q: Clone, A: Clone,

Source§

fn clone(&self) -> Head<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 for Head<Q, A>
where Q: Debug, A: Debug,

Source§

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

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

impl<Q, A> Default for Head<Q, A>
where Q: Default, A: Default,

Source§

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

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

impl<Q, A> Display for Head<Q, A>
where Q: Display, A: Display,

Source§

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

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

impl<Q, A> Driver<Q, A> for Head<Q, usize>
where Q: RawState, Head<Q, usize>: for<'a> Read<&'a mut [A], Output = &'a A>,

Source§

fn current_position(&self) -> usize

returns the current position of the driver.
Source§

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

returns a view of the current state of the driver.
Source§

impl<Q, S> From<(Q, S)> for Head<Q, S>

Source§

fn from(_: (Q, S)) -> Head<Q, S>

Converts to this type from the input type.
Source§

impl<Q, S> From<(State<Q>, S)> for Head<Q, S>

Source§

fn from(_: (State<Q>, S)) -> Head<Q, S>

Converts to this type from the input type.
Source§

impl<Q, S> From<S> for Head<Q, S>
where Q: Default,

Source§

fn from(symbol: S) -> Head<Q, S>

Converts to this type from the input type.
Source§

impl<Q, A> Hash for Head<Q, A>
where Q: Hash, A: Hash,

Source§

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

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> HeadRepr for Head<Q, A>
where Q: RawState,

Source§

fn new(state: Q, symbol: A) -> Head<Q, A>

creates a new head from the given state and symbol

Source§

fn from_state(state: Self::State) -> Self
where Self::Symbol: Default,

create a new head from the given state, using a default symbol
Source§

fn from_symbol(symbol: Self::Symbol) -> Self
where Self::State: Default,

create a new head from the given symbol, using a default state
Source§

impl<Q, A> Index<Head<Q, A>> for InstructionSet<Q, A>
where Q: RawState + PartialEq, A: PartialEq,

Source§

type Output = Tail<Q, A>

The returned type after indexing.
Source§

fn index( &self, index: Head<Q, A>, ) -> &<InstructionSet<Q, A> as Index<Head<Q, A>>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<Q, A> Ord for Head<Q, A>
where Q: Ord, A: Ord,

Source§

fn cmp(&self, other: &Head<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, A> PartialEq<(Q, A)> for Head<Q, A>
where State<Q>: PartialEq, Q: PartialEq, A: PartialEq,

Source§

fn eq(&self, _: &(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> PartialEq<(State<Q>, A)> for Head<Q, A>
where Q: PartialEq, A: PartialEq,

Source§

fn eq(&self, _: &(State<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> PartialEq<Head<Q, A>> for State<&Q>
where Q: PartialEq,

Source§

fn eq(&self, head: &Head<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> PartialEq<Head<Q, A>> for State<Q>
where Q: PartialEq,

Source§

fn eq(&self, head: &Head<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, 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<'a, Q, A> PartialEq<State<&'a Q>> for Head<Q, A>
where Q: PartialEq,

Source§

fn eq(&self, state: &State<&'a Q>) -> 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<State<Q>> for Head<Q, A>
where Q: PartialEq,

Source§

fn eq(&self, state: &State<Q>) -> 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 for Head<Q, A>
where Q: PartialEq, A: PartialEq,

Source§

fn eq(&self, other: &Head<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 for Head<Q, A>
where Q: PartialOrd, A: PartialOrd,

Source§

fn partial_cmp(&self, other: &Head<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, A> RawHead for Head<Q, A>
where Q: RawState,

Source§

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

returns an immutable reference to the state.

Source§

fn symbol(&self) -> &A

returns an immutable reference to the symbol.

Source§

type State = Q

Source§

type Symbol = A

Source§

impl<Q, A> RawHeadMut for Head<Q, A>
where Q: RawState,

Source§

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

returns a mutable reference to the state.

Source§

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

returns a mutable reference to the symbol.

Source§

impl<'a, Q, A> Read<&'a [A]> for &Head<Q, usize>
where Q: RawState,

Source§

type Output = &'a A

Source§

type Error = Error

Source§

fn read( self, rhs: &'a [A], ) -> Result<<&Head<Q, usize> as Read<&'a [A]>>::Output, <&Head<Q, usize> as Read<&'a [A]>>::Error>

Source§

impl<'a, Q, A> Read<&'a [A]> for &mut Head<Q, usize>
where Q: RawState,

Source§

type Output = &'a A

Source§

type Error = Error

Source§

fn read( self, rhs: &'a [A], ) -> Result<<&mut Head<Q, usize> as Read<&'a [A]>>::Output, <&mut Head<Q, usize> as Read<&'a [A]>>::Error>

Source§

impl<'a, Q, A> Read<&'a [A]> for Head<Q, usize>
where Q: RawState,

Source§

type Output = &'a A

Source§

type Error = Error

Source§

fn read( self, rhs: &'a [A], ) -> Result<<Head<Q, usize> as Read<&'a [A]>>::Output, <Head<Q, usize> as Read<&'a [A]>>::Error>

Source§

impl<'a, Q, A> Read<&'a mut [A]> for &Head<Q, usize>
where Q: RawState,

Source§

type Error = Error

Source§

type Output = &'a A

Source§

fn read( self, rhs: &'a mut [A], ) -> Result<<&Head<Q, usize> as Read<&'a mut [A]>>::Output, <&Head<Q, usize> as Read<&'a mut [A]>>::Error>

Source§

impl<'a, Q, A> Read<&'a mut [A]> for &mut Head<Q, usize>
where Q: RawState,

Source§

type Error = Error

Source§

type Output = &'a A

Source§

fn read( self, rhs: &'a mut [A], ) -> Result<<&mut Head<Q, usize> as Read<&'a mut [A]>>::Output, <&mut Head<Q, usize> as Read<&'a mut [A]>>::Error>

Source§

impl<'a, Q, A> Read<&'a mut [A]> for Head<Q, usize>
where Q: RawState,

Source§

type Output = &'a A

Source§

type Error = Error

Source§

fn read( self, rhs: &'a mut [A], ) -> Result<<Head<Q, usize> as Read<&'a mut [A]>>::Output, <Head<Q, usize> as Read<&'a mut [A]>>::Error>

Source§

impl<Q, A, T> ReadBuf<T> for Head<Q, A>
where Q: RawState, A: Copy + SliceIndex<[T], Output = T>, <A as SliceIndex<[T]>>::Output: Clone,

Source§

type Buf<_T> = [_T]

Source§

type Output = <A as SliceIndex<[T]>>::Output

Source§

fn read( &mut self, rhs: &mut <Head<Q, A> as ReadBuf<T>>::Buf<T>, ) -> <Head<Q, A> as ReadBuf<T>>::Output

Source§

impl<Q, A> Copy for Head<Q, A>
where Q: Copy, A: Copy,

Source§

impl<Q, A> Eq for Head<Q, A>
where Q: Eq, A: Eq,

Source§

impl<Q, A> StructuralPartialEq for Head<Q, A>

Auto Trait Implementations§

§

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

§

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

§

impl<Q, A> Send for Head<Q, A>
where A: Send, Q: Send,

§

impl<Q, A> Sync for Head<Q, A>
where A: Sync, Q: Sync,

§

impl<Q, A> Unpin for Head<Q, A>
where A: Unpin, Q: Unpin,

§

impl<Q, A> UnwindSafe for Head<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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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<U, Q> Stateful<Q> for U
where U: Borrow<State<Q>>, Q: RawState,

Source§

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

returns a reference to the current state
Source§

impl<S> Symbolic for S
where S: 'static + Clone + Default + Eq + Ord + Send + Sync + Debug + Display + Hash,

Source§

fn __private__(&self) -> Seal

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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