1 | /// The representation of data, rows and columns of a [`Grid`]. |
2 | /// |
3 | /// [`Grid`]: crate::grid::iterable::Grid |
4 | pub trait IntoRecords { |
5 | /// A string representation of a [`Grid`] cell. |
6 | /// |
7 | /// [`Grid`]: crate::grid::iterable::Grid |
8 | type Cell: AsRef<str>; |
9 | |
10 | /// Cell iterator inside a row. |
11 | type IterColumns: IntoIterator<Item = Self::Cell>; |
12 | |
13 | /// Rows iterator. |
14 | type IterRows: IntoIterator<Item = Self::IterColumns>; |
15 | |
16 | /// Returns an iterator over rows. |
17 | fn iter_rows(self) -> Self::IterRows; |
18 | } |
19 | |
20 | impl<T> IntoRecords for T |
21 | where |
22 | T: IntoIterator, |
23 | <T as IntoIterator>::Item: IntoIterator, |
24 | <<T as IntoIterator>::Item as IntoIterator>::Item: AsRef<str>, |
25 | { |
26 | type Cell = <<T as IntoIterator>::Item as IntoIterator>::Item; |
27 | type IterColumns = <T as IntoIterator>::Item; |
28 | type IterRows = <T as IntoIterator>::IntoIter; |
29 | |
30 | fn iter_rows(self) -> Self::IterRows { |
31 | self.into_iter() |
32 | } |
33 | } |
34 | |