pub struct Coords {
    pub row: CoordValue,
    pub column: CoordValue,
}
Expand description

Coordinates of a single cell of the board. hexgame uses a zero-based (row, column)-format analogous to matrix-indices.

The following diagram shows on the left the format used by Coords and on the right the “c4” format similar to Chess that is commonly used in the literature. Note that the order of row-index and column-index is swapped between both formats: The marked cell has coordinates (1, 3) and d2, respectively.

 0  1  2  3  4           a  b  c  d  e
0\.  .  .  .  .\0       1\.  .  .  .  .\1
 1\.  .  .  ●  .\1       2\.  .  .  ●  .\2
  2\.  .  .  .  .\2       3\.  .  .  .  .\3
   3\.  .  .  .  .\3       4\.  .  .  .  .\4
    4\.  .  .  .  .\4       5\.  .  .  .  .\5
       0  1  2  3  4           a  b  c  d  e

The from_str and to_string methods can be used to convert between the formats.

use std::str::FromStr;
let coords = Coords::new(7, 0);
// Note the different order!
assert_eq!(coords.to_string(), "a8");

let other_coords = Coords::from_str("a8").unwrap();
assert_eq!(coords, other_coords);

Fields

row: CoordValue

Zero-based row index, counted from top to bottom.

column: CoordValue

Zero-based column index, counted from left to right.

Implementations

Create a new Coords instance. Watch out: Order of parameters is different from the commonly used “c4” format.

Return whether this coordinate exist on a board of the given size.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Parse a coordinate from “c4” format.

The associated error which can be returned from parsing.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.