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
pub trait Grid<T> {
#[must_use]
fn new(width: usize, height: usize) -> Self;
/// Sets the value at the specified position
///
/// returns: the old value
fn set(&mut self, x: usize, y: usize, value: T) -> T;
/// Get the current value at the specified position
fn get(&self, x: usize, y: usize) -> T;
/// Sets all cells in the grid to the specified value
fn fill(&mut self, value: T);
/// the size in x-direction
fn width(&self) -> usize;
/// the height in y-direction
fn height(&self) -> usize;
/// Creates a new instance containing the specified window.
///
/// Use concrete types to avoid boxing.
///
/// # Arguments
///
/// * `x`: column of the top left cell
/// * `y`: row of the top left cell
/// * `w`: size of window in x-direction
/// * `h`: size of window in y-direction
///
/// returns: Self
///
/// # Examples
/// To avoid boxing, this example is using the concrete type `ByteGrid`.
/// ```
/// use servicepoint2::{ByteGrid, Grid};
/// fn split(grid: ByteGrid) -> (ByteGrid, ByteGrid) {
/// assert!(grid.width() >= 2);
/// let split_x = grid.width() / 2;
/// let right_w = grid.width() - split_x;
///
/// let left = grid.window(0, 0, split_x, grid.height());
/// let right = grid.window(split_x, 0, right_w, grid.height());
/// (left, right)
/// }
///
/// let (l, r) = split(ByteGrid::new(9, 5));
/// ```
#[must_use]
fn window(&self, x: usize, y: usize, w: usize, h: usize) -> Self;
}