Dir

Enum Dir 

Source
pub enum Dir {
    N = 0,
    NE = 1,
    E = 2,
    SE = 3,
    S = 4,
    SW = 5,
    W = 6,
    NW = 7,
}
Expand description

Direction type.

This type represents a relative movement of one square.

It’s a building block for paths, iterating on a super::Pos neighbors, etc. It effectively represents the edges in a graph, while the Pos type represents nodes.

Variants§

§

N = 0

North, or up

§

NE = 1

Northeast

§

E = 2

East, or right

§

SE = 3

Southeast

§

S = 4

South, or down

§

SW = 5

Southwest

§

W = 6

West, or left

§

NW = 7

Norwest

Implementations§

Source§

impl Dir

Source

pub const SIZE: usize = 8usize

Number of possible directions

Source

pub const ALL8: [Self; 8]

All 8 possible values in enum order

Used to convert a usize into a Dir value via indexing.

Source

pub const ALL4: [Self; 4]

The 4 “major” cardinal directions.

Source

pub const NAMES_CARDINAL: [&'static str; 8]

The “cardinal” names of all corresponding Dir values.

Used to convert a Dir value into a &’static str via indexing.

Source

pub const NAMES_UTF8: [&'static str; 8]

The UTF-8 symbol corresponding to Dir values.

Used to convert a Dir value into a &’static str via indexing.

Source

pub const NAMES_UTF8_CHAR: [char; 8]

The UTF-8 symbol corresponding to Dir values.

Used to convert a Dir value into a char via indexing.

Source

pub const NAMES_ASCII: [&'static str; 8]

The ASCII symbol corresponding to Dir values.

Used to convert a Dir value into a &’static str via indexing.

Source

pub const NAMES_ASCII_CHAR: [char; 8]

The ASCII symbol corresponding to Dir values.

Used to convert a Dir value into a char via indexing.

Source

pub const fn is_diagonal(&self) -> bool

Return true if the Dir is one of the diagonals: NE, SE, SW or NW.

Source

pub const fn name_cardinal(&self) -> &'static str

Return the “cardinal” name of the Dir

Source

pub const fn name_utf8(&self) -> &'static str

Return the UTF-8 arrow corresponding to the Dir

Source

pub const fn name_utf8_char(&self) -> char

Return the UTF-8 arrow corresponding to the Dir

Source

pub const fn name_ascii(&self) -> &'static str

Return the UTF-8 arrow corresponding to the Dir

Source

pub const fn name_ascii_char(&self) -> char

Return the UTF-8 arrow corresponding to the Dir

Source

pub const fn flip(&self) -> Dir

Flip the direction: N -> S, E -> W, etc.

Source

pub const fn rotate(&self, other: &Dir) -> Dir

Rotate a Dir using the angle given by the other Dir argument

Source

pub const fn next<const D: bool>(&self) -> Option<Self>

Return the next Dir in clockwise order, or None if self is the last one.

This function takes a generic const argument D that indicates if diagonals should be considered or not. If considered, the last Dir is Dir::NW, otherwise it’s Dir::S.

Source

pub fn iter<const D: bool>() -> DirIter<D>

Returns an iterator that returns all possible values for the Dir type used, in clockwise order.

This function takes a generic const argument D that indicates if diagonals should be in the iteration or not.

Trait Implementations§

Source§

impl<T: BoundedInt, U: BoundedInt> Add<Dir> for &(T, U)

Source§

type Output = Result<(T, U), Error>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<const XMAX: u16, const YMAX: u16> Add<Dir> for &Pos<XMAX, YMAX>
where (BoundedU16<0, XMAX>, BoundedU16<0, YMAX>): Add<Dir, Output = Result<(BoundedU16<0, XMAX>, BoundedU16<0, YMAX>), Error>>,

Source§

type Output = Result<Pos<XMAX, YMAX>, Error>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: BoundedInt, U: BoundedInt> Add<Dir> for (T, U)

Source§

type Output = Result<(T, U), Error>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<const XMAX: u16, const YMAX: u16> Add<Dir> for Pos<XMAX, YMAX>
where (BoundedU16<0, XMAX>, BoundedU16<0, YMAX>): Add<Dir, Output = Result<(BoundedU16<0, XMAX>, BoundedU16<0, YMAX>), Error>>,

Source§

type Output = Result<Pos<XMAX, YMAX>, Error>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for Dir

Source§

type Output = Dir

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Dir

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl Clone for Dir

Source§

fn clone(&self) -> Dir

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 Dir

Source§

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

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

impl Default for Dir

Source§

fn default() -> Dir

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

impl Display for Dir

Source§

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

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

impl From<Dir> for (i128, i128)

Source§

fn from(dir: Dir) -> Self

Converts to this type from the input type.
Source§

impl From<Dir> for (i16, i16)

Source§

fn from(dir: Dir) -> Self

Converts to this type from the input type.
Source§

impl From<Dir> for (i32, i32)

Source§

fn from(dir: Dir) -> Self

Converts to this type from the input type.
Source§

impl From<Dir> for (i64, i64)

Source§

fn from(dir: Dir) -> Self

Converts to this type from the input type.
Source§

impl From<Dir> for (i8, i8)

Source§

fn from(dir: Dir) -> Self

Converts to this type from the input type.
Source§

impl From<Dir> for (isize, isize)

Source§

fn from(dir: Dir) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Dir

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Dir

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 Neg for Dir

Source§

type Output = Dir

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Ord for Dir

Source§

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

Source§

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

Source§

fn partial_cmp(&self, other: &Dir) -> 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 TryFrom<&(i128, i128)> for Dir

Source§

type Error = Error

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

fn try_from(xy: &(i128, i128)) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&(i16, i16)> for Dir

Source§

type Error = Error

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

fn try_from(xy: &(i16, i16)) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&(i32, i32)> for Dir

Source§

type Error = Error

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

fn try_from(xy: &(i32, i32)) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&(i64, i64)> for Dir

Source§

type Error = Error

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

fn try_from(xy: &(i64, i64)) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&(i8, i8)> for Dir

Source§

type Error = Error

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

fn try_from(xy: &(i8, i8)) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&(isize, isize)> for Dir

Source§

type Error = Error

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

fn try_from(xy: &(isize, isize)) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T> TryFrom<(T, T)> for Dir
where Dir: for<'a> TryFrom<&'a (T, T), Error = Error>,

Source§

type Error = Error

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

fn try_from(xy: (T, T)) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<char> for Dir

Source§

type Error = Error

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

fn try_from(c: char) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Dir

Source§

impl Eq for Dir

Source§

impl StructuralPartialEq for Dir

Auto Trait Implementations§

§

impl Freeze for Dir

§

impl RefUnwindSafe for Dir

§

impl Send for Dir

§

impl Sync for Dir

§

impl Unpin for Dir

§

impl UnwindSafe for Dir

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