1pub type Row = u16;
2pub type Col = u16;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub struct Pos {
9 pub offset: usize,
11 pub row: Row,
13 pub col: Col,
15}
16
17impl Pos {
18 pub const fn start() -> Self {
20 Pos {
21 offset: 0,
22 row: 1,
23 col: 1,
24 }
25 }
26
27 pub const fn right(self) -> Self {
29 Pos {
30 offset: self.offset + 1,
31 row: self.row,
32 col: self.col + 1,
33 }
34 }
35
36 pub const fn down(self) -> Self {
38 Pos {
39 offset: self.offset + 1,
40 row: self.row + 1,
41 col: 1,
42 }
43 }
44}
45
46impl Default for Pos {
47 fn default() -> Self {
48 Pos::start()
49 }
50}
51
52impl std::fmt::Display for Pos {
53 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
54 let Pos { offset, row, col } = *self;
55 write!(f, "Pos(offset {offset} column {col} row {row})")
56 }
57}