fn neighbours(x: usize, y: usize, size: usize) -> impl Iterator<Item = (usize, usize)> {
    [
        (x as isize - 1, y as isize),
        (x as isize, y as isize - 1),
        (x as isize, y as isize + 1),
        (x as isize + 1, y as isize),
    ]
    .into_iter()
    .filter_map(move |(i, j)| {
        if i >= 0 && j >= 0 && i < size as isize && j < size as isize {
            Some((i as usize, j as usize))
        } else {
            None
        }
    })
}
/// helper function to iterate over the neighbours of a point
helper function to iterate over the neighbours of a point
helper function to iterate over the neighbours of a point
fn neighbours(x: usize, y: usize, size: usize) -> impl Iterator<Item = (usize, usize)> {
    [
        (x as isize - 1, y as isize),
        (x as isize, y as isize - 1),
        (x as isize, y as isize + 1),
        (x as isize + 1, y as isize),
    ]
    .into_iter()
    .filter_map(move |(i, j)| {
        if i >= 0 && j >= 0 && i < size as isize && j < size as isize {
            Some((i as usize, j as usize))
        } else {
            None
        }
    })
}
fn neighbours ( x : usize , y : usize , size : usize ) -> impl Iterator < Item = ( usize , usize ) > { [ ( x as isize - 1 , y as isize ) , ( x as isize , y as isize - 1 ) , ( x as isize , y as isize + 1 ) , ( x as isize + 1 , y as isize ) , ] . into_iter ( ) . filter_map ( move | ( i , j ) | { if i >= 0 && j >= 0 && i < size as isize && j < size as isize { Some ( ( i as usize , j as usize ) ) } else { None } } ) }
helper function to iterate over the neighbours of a point
helper function to iterate over the neighbours of a point
x
usize
y
usize
size
usize