[][src]Enum thud::Direction

pub enum Direction {
    Up,
    UpRight,
    Right,
    DownRight,
    Down,
    DownLeft,
    Left,
    UpLeft,
}

A cardinal direction on a Board

Variants

Up
UpRight
Right
DownRight
Down
DownLeft
Left
UpLeft

Methods

impl Direction[src]

pub fn all() -> Vec<Self>[src]

Get a Vec containing all the different possible Directions

pub fn from_num(dir: usize) -> Result<Self, ThudError>[src]

pub fn from_route(start: Coord, end: Coord) -> Result<Direction, ThudError>[src]

Use two Coords to get a Direction from one to the other

Returns Err(ThudError::MathError) if:

  • The two Coords are not plottable on a straight line together
  • The two Coords are equal

pub fn modifier(&self) -> (isize, isize)[src]

Get a tuple representing the changes needed to a Coord in order to "move" it in the Direction given by self.

Example:

use thud::Direction;

assert_eq!(Direction::Up.modifier(), (0, 1));
assert_eq!(Direction::DownLeft.modifier(), (-1, -1));

pub fn modify(&self, loc: Coord) -> Result<Coord, ThudError>[src]

Return a Coord equal to loc offset by one square in the direction given by self.

Returns Err(ThudError::MathError) if this movement would place the Coord out of bounds.

pub fn opposite(&self) -> Self[src]

Get the "opposite" Direction to self.

For example:

use thud::Direction;

assert_eq!(Direction::Up.opposite(), Direction::Down);

Trait Implementations

impl Clone for Direction[src]

impl Copy for Direction[src]

impl Debug for Direction[src]

impl PartialEq<Direction> for Direction[src]

impl StructuralPartialEq for Direction[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.