grid_cell/
spot.rs

1use crate::{Coordinate, First, Fourth, GridCell, Second, Third};
2
3pub struct Spot {
4    pub coordinate: Coordinate,
5    pub(crate) first: Option<GridCell<First>>,
6    pub(crate) second: Option<GridCell<Second>>,
7    pub(crate) third: Option<GridCell<Third>>,
8    pub(crate) fourth: Option<GridCell<Fourth>>,
9}
10
11impl Spot {
12    pub fn new(coordinate: Coordinate) -> Spot {
13        Spot {
14            coordinate,
15            first: None,
16            second: None,
17            third: None,
18            fourth: None,
19        }
20    }
21
22    pub fn as_first_cell(&mut self) -> &GridCell<First> {
23        if self.first.is_none() {
24            self.first = Some(self.coordinate.first_cell());
25        }
26        self.first.as_ref().unwrap()
27    }
28
29    pub fn as_second_cell(&mut self) -> &GridCell<Second> {
30        if self.second.is_none() {
31            let coordinate = self.coordinate;
32            self.second = Some(coordinate.second_cell(self.as_first_cell()));
33        }
34        self.second.as_ref().unwrap()
35    }
36
37    pub fn as_third_cell(&mut self) -> &GridCell<Third> {
38        if self.third.is_none() {
39            let coordinate = self.coordinate;
40            self.third = Some(coordinate.third_cell(self.as_second_cell()))
41        }
42        self.third.as_ref().unwrap()
43    }
44
45    pub fn as_fourth_cell(&mut self) -> &GridCell<Fourth> {
46        if self.fourth.is_none() {
47            let coordinate = self.coordinate;
48            self.fourth = Some(coordinate.fourth_cell(self.as_third_cell()))
49        }
50        self.fourth.as_ref().unwrap()
51    }
52
53    pub fn to_first_cell(mut self) -> GridCell<First> {
54        self.as_first_cell();
55        self.first.unwrap()
56    }
57
58    pub fn to_second_cell(mut self) -> GridCell<Second> {
59        self.as_second_cell();
60        self.second.unwrap()
61    }
62
63    pub fn to_third_cell(mut self) -> GridCell<Third> {
64        self.as_third_cell();
65        self.third.unwrap()
66    }
67
68    pub fn to_fourth_cell(mut self) -> GridCell<Fourth> {
69        self.as_fourth_cell();
70        self.fourth.unwrap()
71    }
72}