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
/// The representation of data, rows and columns of a [`Grid`].
///
/// [`Grid`]: crate::grid::iterable::Grid
pub trait IntoRecords {
    /// A string representation of a [`Grid`] cell.
    ///
    /// [`Grid`]: crate::grid::iterable::Grid
    type Cell;

    /// Cell iterator inside a row.
    type IterColumns: IntoIterator<Item = Self::Cell>;

    /// Rows iterator.
    type IterRows: IntoIterator<Item = Self::IterColumns>;

    /// Returns an iterator over rows.
    fn iter_rows(self) -> Self::IterRows;
}

impl<T> IntoRecords for T
where
    T: IntoIterator,
    <T as IntoIterator>::Item: IntoIterator,
{
    type Cell = <<T as IntoIterator>::Item as IntoIterator>::Item;
    type IterColumns = <T as IntoIterator>::Item;
    type IterRows = <T as IntoIterator>::IntoIter;

    fn iter_rows(self) -> Self::IterRows {
        self.into_iter()
    }
}