Struct Actor

Source
pub struct Actor<Q, A> { /* private fields */ }
Expand description

An Actor is an implementation of a Turing machine with a moving head (TMH).

The model contains the following components:

  • alpha: the input alphabet
  • head: the head of the tape

Implementations§

Source§

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

Source

pub fn new( alpha: impl IntoIterator<Item = A>, state: State<Q>, symbol: usize, ) -> Self

Source

pub fn from_state(state: State<Q>) -> Self

Constructs a new Actor with the given state; assumes the tape is empty and the head is located at 0.

Source

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

returns an immutable reference to the head of the tape

Source

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

returns a mutable reference to the head of the tape

Source

pub const fn tape(&self) -> &Vec<A>

returns an immutable reference to the tape

Source

pub const fn tape_mut(&mut self) -> &mut Vec<A>

returns a mutable reference of the tape

Source

pub fn set_head(&mut self, head: Head<Q, usize>) -> &mut Self

update the current head and return a mutable reference to the actor

Source

pub fn set_position(&mut self, symbol: usize) -> &mut Self

updates the current position of the head and returns a mutable reference to the actor

Source

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

updates the current state of the head and returns a mutable reference to the actor

Source

pub fn set_tape(&mut self, tape: Vec<A>) -> &mut Self

update the current tape and return a mutable reference to the actor

Source

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

Consumes the current instance and returns a new instance with the given head

Source

pub fn with_position(self, symbol: usize) -> Self

Consumes the current instance and returns a new instance with the given position

Source

pub fn with_state(self, state: State<Q>) -> Self

Consumes the current instance and returns a new instance with the given state

Source

pub fn with_tape<I>(self, alpha: I) -> Self
where I: IntoIterator<Item = A>,

Consumes the current instance and returns a new instance with the given alphabet

Source

pub fn head_ref(&self) -> Head<&Q, usize>

returns an instance of the Head with an immutable reference to the state’s inner value

Source

pub fn position(&self) -> usize

returns the current position of the head on the tape

Source

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

returns an instance of the state with an immutable reference to the inner value

Source

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

returns an instance of the state with a mutable reference to the inner value

Source

pub fn execute(self, program: RuleSet<Q, A>) -> Executor<Q, A>

Executes the given program; the method is lazy, meaning it will not compute immediately but will return an Executor that is better suited for managing the runtime.

Source

pub fn is_empty(&self) -> bool

Checks if the tape is empty

Source

pub fn is_halted(&self) -> bool
where Q: 'static,

Checks if the tape is halted

Source

pub fn len(&self) -> usize

returns the length of the tape

Source

pub fn read(&self) -> Result<Head<&Q, &A>>

Reads the current symbol at the head of the tape

Source

pub fn write(&mut self, value: A)

Writes the given symbol to the tape

Trait Implementations§

Source§

impl<Q: Clone, A: Clone> Clone for Actor<Q, A>

Source§

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

Source§

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

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

impl<Q: Default, A: Default> Default for Actor<Q, A>

Source§

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

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

impl<Q, S> Display for Actor<Q, S>
where Q: RawState, S: Display,

Source§

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

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

impl<Q, S> Handle<(Direction, Head<Q, S>)> for Actor<Q, S>
where Q: RawState + Clone + PartialEq, S: Symbolic,

Source§

type Output = Head<Q, usize>

Source§

fn handle(&mut self, (direction, _): (Direction, Head<Q, S>)) -> Self::Output

Source§

impl<Q, S> Handle<(Direction, State<Q>, S)> for Actor<Q, S>
where Q: RawState + Clone + PartialEq, S: Symbolic,

Source§

type Output = Head<Q, usize>

Source§

fn handle( &mut self, (direction, state, symbol): (Direction, State<Q>, S), ) -> Self::Output

Source§

impl<Q, S> Handle<Tail<Q, S>> for Actor<Q, S>
where Q: RawState + Clone + PartialEq, S: Symbolic,

Source§

type Output = Head<Q, usize>

Source§

fn handle(&mut self, _: Tail<Q, S>) -> Self::Output

Source§

impl<Q: Hash, A: Hash> Hash for Actor<Q, A>

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: PartialEq, A: PartialEq> PartialEq for Actor<Q, A>

Source§

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

Source§

fn partial_cmp(&self, other: &Actor<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: Eq, A: Eq> Eq for Actor<Q, A>

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<Q, A> UnwindSafe for Actor<Q, A>
where Q: UnwindSafe, A: 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<K, S> Identity<K> for S
where S: Borrow<K>, K: Identifier,

Source§

type Item = S

Source§

fn get(&self) -> &<S as Identity<K>>::Item

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more