maze/
maze_point_offset.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::fmt;

#[allow(dead_code)]
#[derive(Clone, Debug)]
/// Represents an offset between maze points
pub struct MazePointOffset {
    /// Row offset
    pub row: i32,
    /// Column offset
    pub col: i32,
}

impl fmt::Display for MazePointOffset {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "[{}, {}]", self.row, self.col)
    }
}

#[test]
fn should_have_expected_display_format() {
    let o = MazePointOffset { row: -1, col: 0 };
    let s = format!("{}", o);
    assert_eq!(s, "[-1, 0]");
}