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
mod cell_iterator;
mod output;

use super::cell::Cell;
use cell_iterator::CellIterator;
use output::Output;

pub type Input = Vec<Cell>;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Row {
  input: Input,
  output: Output,
}

impl Row {
  pub fn input_len(&self) -> usize {
    self.input.len()
  }

  pub fn input_eq(&self, input: &[Cell]) -> bool {
    self.input.iter().eq(input)
  }

  pub fn input_cells<'a>(&'a self) -> impl Iterator<Item = &'a Cell> {
    CellIterator::new(&self.input)
  }
}

impl Row {
  pub fn new<TCell, TInput, TOutput>(input: TInput, output: TOutput) -> Self
  where
    TCell: Into<Cell>,
    TInput: IntoIterator<Item = TCell>,
    TOutput: Into<Output>,
  {
    Self {
      input: input.into_iter().map(Into::into).collect(),
      output: output.into(),
    }
  }
}