Trait aoc_grid::GridPos

source ·
pub trait GridPos<const DIMS: usize>: Copy + Debug + Default + Eq + Sized {
    type Coord: Int;

    // Required methods
    fn to_array(self) -> [Self::Coord; DIMS];
    fn from_array(array: [Self::Coord; DIMS]) -> Self;

    // Provided methods
    fn map<MapFn, Output>(self, map_fn: MapFn) -> [Output; DIMS]
       where MapFn: FnMut(Self::Coord) -> Output { ... }
    fn to_native(self, start: Self) -> Option<Self> { ... }
    fn native_to_index(self, size: Self) -> Option<isize> { ... }
    fn from_native(native: Self, start: Self) -> Option<Self> { ... }
}
Expand description

Trait for values to use as indices for a GridView.

For example, a two dimensional grid might be indexed with a struct containing an x and a y coordinate.

This trait provides methods to translate whatever coordinate system is in use to and from a single usize value.

Required Associated Types§

Required Methods§

source

fn to_array(self) -> [Self::Coord; DIMS]

source

fn from_array(array: [Self::Coord; DIMS]) -> Self

Provided Methods§

source

fn map<MapFn, Output>(self, map_fn: MapFn) -> [Output; DIMS]where MapFn: FnMut(Self::Coord) -> Output,

source

fn to_native(self, start: Self) -> Option<Self>

source

fn native_to_index(self, size: Self) -> Option<isize>

source

fn from_native(native: Self, start: Self) -> Option<Self>

Implementations on Foreign Types§

source§

impl<Val: Int> GridPos<2> for PosGeo<Val>

§

type Coord = Val

source§

fn to_array(self) -> [Val; 2]

source§

fn from_array(array: [Val; 2]) -> Self

source§

impl<Val: Int> GridPos<4> for PosWXYZ<Val>

§

type Coord = Val

source§

fn to_array(self) -> [Val; 4]

source§

fn from_array(array: [Val; 4]) -> Self

source§

impl<Val: Int> GridPos<2> for PosRowCol<Val>

§

type Coord = Val

source§

fn to_array(self) -> [Val; 2]

source§

fn from_array(array: [Val; 2]) -> Self

source§

impl<Val: Int> GridPos<4> for PosXYZW<Val>

§

type Coord = Val

source§

fn to_array(self) -> [Val; 4]

source§

fn from_array(array: [Val; 4]) -> Self

source§

impl<Val: Int> GridPos<3> for PosXYZ<Val>

§

type Coord = Val

source§

fn to_array(self) -> [Val; 3]

source§

fn from_array(array: [Val; 3]) -> Self

source§

impl<Val: Int> GridPos<2> for PosXY<Val>

§

type Coord = Val

source§

fn to_array(self) -> [Val; 2]

source§

fn from_array(array: [Val; 2]) -> Self

source§

impl<Val: Int> GridPos<2> for PosGeoHexLat<Val>

§

type Coord = Val

source§

fn to_array(self) -> [Val; 2]

source§

fn from_array(array: [Val; 2]) -> Self

source§

impl<Val: Int> GridPos<2> for PosYX<Val>

§

type Coord = Val

source§

fn to_array(self) -> [Val; 2]

source§

fn from_array(array: [Val; 2]) -> Self

Implementors§