Enum Direction

Source
pub enum Direction {
    Left = -1,
    Right = 1,
    Stay = 0,
}
Expand description

Direction enumerates the various directions a head can move, namely: left, right, and stay.

The included methods and implementations aim to streamline the conversion between Direction and other types.

Variants§

§

Left = -1

Represents a single left shift

§

Right = 1

Represents a single right shift

§

Stay = 0

Represents no movement

Implementations§

Source§

impl Direction

Source

pub fn from_u8(value: u8) -> Self

Converts an instance of the named type into a Direction.

Source

pub fn from_u16(value: u16) -> Self

Converts an instance of the named type into a Direction.

Source

pub fn from_u32(value: u32) -> Self

Converts an instance of the named type into a Direction.

Source

pub fn from_u64(value: u64) -> Self

Converts an instance of the named type into a Direction.

Source

pub fn from_u128(value: u128) -> Self

Converts an instance of the named type into a Direction.

Source

pub fn from_usize(value: usize) -> Self

Converts an instance of the named type into a Direction.

Source§

impl Direction

Source

pub fn left() -> Self

Source

pub fn right() -> Self

Source

pub fn stay() -> Self

Source§

impl Direction

Source

pub const fn is_left(&self) -> bool

Returns true if the enum is Direction::Left otherwise false

Source

pub const fn is_right(&self) -> bool

Returns true if the enum is Direction::Right otherwise false

Source

pub const fn is_stay(&self) -> bool

Returns true if the enum is Direction::Stay otherwise false

Source§

impl Direction

Source

pub fn from_i8(value: i8) -> Self

Converts an i8 value into a Direction by taking the modulus of the value. The function uses a modulator of 2 to determine the direction since there are only two actionable directions (left and right).

Source

pub fn from_char(value: char) -> Self

Converts a char value into a direction; matches the value to the corresponding direction.

Source

pub fn from_str(value: &str) -> Self

Converts a str value into a Direction by matching the value to the corresponding variant; defaults to Stay if the value does not match accepted representations of neither left nor right.

Source

pub fn as_char(&self) -> char

Returns a char representation of the direction.

§standard char representation

‘L’ => Direction::Left ‘R’ => Direction::Right ‘S’ => Direction::Stay

Source

pub fn as_str(&self) -> &str

Returns a str representation of the direction.

Source

pub fn apply_unsigned(self, cur: usize) -> usize

Applies the shift to the given position in the direction specified by the current instance. This is done using the wrapping_add_signed method.

Trait Implementations§

Source§

impl Add<Direction> for i128

Source§

type Output = i128

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for i16

Source§

type Output = i16

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for i32

Source§

type Output = i32

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for i64

Source§

type Output = i64

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for i8

Source§

type Output = i8

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for isize

Source§

type Output = isize

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for u128

Source§

type Output = u128

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for u16

Source§

type Output = u16

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for u32

Source§

type Output = u32

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for u64

Source§

type Output = u64

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for u8

Source§

type Output = u8

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction> for usize

Source§

type Output = usize

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> Add<T> for Direction
where T: Add<Output = T> + Sub<Output = T> + One,

Source§

type Output = T

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<Direction> for i128

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for i16

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for i32

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for i64

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for i8

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for isize

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for u128

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for u16

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for u32

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for u64

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for u8

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AddAssign<Direction> for usize

Source§

fn add_assign(&mut self, rhs: Direction)

Performs the += operation. Read more
Source§

impl AsRef<str> for Direction

Source§

fn as_ref(&self) -> &str

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

impl Clone for Direction

Source§

fn clone(&self) -> Direction

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 Debug for Direction

Source§

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

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

impl Default for Direction

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Direction

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 Display for Direction

Source§

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

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

impl EnumCount for Direction

Source§

const COUNT: usize = 3usize

Source§

impl From<&str> for Direction

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<char> for Direction

Source§

fn from(value: char) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for Direction

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Direction

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Direction

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Direction

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Direction

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Direction

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Direction

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Direction

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Direction

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Direction

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Direction

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Direction

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl Hash for Direction

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 IntoEnumIterator for Direction

Source§

impl Ord for Direction

Source§

fn cmp(&self, other: &Direction) -> 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 PartialEq for Direction

Source§

fn eq(&self, other: &Direction) -> 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 PartialOrd for Direction

Source§

fn partial_cmp(&self, other: &Direction) -> 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 Serialize for Direction

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 VariantArray for Direction

Source§

const VARIANTS: &'static [Self]

Source§

impl VariantNames for Direction

Source§

const VARIANTS: &'static [&'static str]

Names of the variants of this enum
Source§

impl Copy for Direction

Source§

impl Eq for Direction

Source§

impl StructuralPartialEq for Direction

Auto Trait Implementations§

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> AsDirection for T
where T: Clone + IntoDirection,

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> ErrorKind for T
where T: AsRef<str>,

Source§

fn __private__(&self) -> Seal

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> IntoDirection for T
where T: Into<Direction>,

Source§

impl<T> RawStateKind for T
where T: AsRef<str>,

Source§

fn __private__(&self) -> Seal

Source§

impl<T> StateKind for T
where T: AsRef<str>,

Source§

fn kind(&self) -> &str

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

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

Source§

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