[][src]Struct ingrid::Coordinate

pub struct Coordinate {
    pub x: usize,
    pub y: usize,
}

A two-dimensional coordinate

This structure defines a basic two-dimensional coordinate to index grids. It enables copy semantics to avoid handling ownership and references throughout your code for no significant performance. Also, in practice, you use the coord! macro helper to instantiate coordinates.

Examples

// Create a coordinate to index the top-left element of a grid.
let mut coord1 = coord!(0, 0);

// Copy the coordinate into another variable.
let coord2 = coord1;

// The first variable is still accessible.
coord1.x = 42;
coord1.y += 1;

// Additionally, you could also type the following.
let coord3 = Coordinate::zero();

Fields

x: usize

The coordinate on the X axis.

y: usize

The coordinate on the Y axis.

Methods

impl Coordinate[src]

pub fn new(x: usize, y: usize) -> Coordinate[src]

Construct a new coordinate.

This function constructs a new coordinate from given X and Y values.

Examples

let coord = Coordinate::new(0, 42);

assert_eq!(coord.x, 0);
assert_eq!(coord.y, 42);

pub fn zero() -> Coordinate[src]

Construct a zero coordinate.

This function constructs a 'zero' coordinate which is a coordinate with both x and y values set at 0.

Examples

let coord = Coordinate::zero();

assert_eq!(coord.x, 0);
assert_eq!(coord.y, 0);

Trait Implementations

impl Clone for Coordinate[src]

impl Copy for Coordinate[src]

impl Debug for Coordinate[src]

impl Eq for Coordinate[src]

impl<T> Index<Coordinate> for Grid<T>[src]

type Output = T

The returned type after indexing.

impl<T> IndexMut<Coordinate> for Grid<T>[src]

impl PartialEq<Coordinate> for Coordinate[src]

impl StructuralEq for Coordinate[src]

impl StructuralPartialEq for Coordinate[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.