pub trait Neighbour: Sized {
fn get_neighbour(&self, n: u8) -> Option<Self>;
}
pub trait Neighbours: Neighbour
where
Self: Copy,
{
fn neighbours(&self) -> NeighbourIterator<Self> {
NeighbourIterator {
coord: *self,
count: 0,
}
}
}
pub struct NeighbourIterator<C> {
coord: C,
count: u8,
}
impl<C> Iterator for NeighbourIterator<C>
where
C: Neighbour,
{
type Item = C;
fn next(&mut self) -> Option<C> {
self.count += 1;
self.coord.get_neighbour(self.count - 1)
}
}
impl<C> Neighbours for C where C: Neighbour + Copy {}