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