aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/helper/table_rows.rs
blob: 1fc14bbfeabd9fc2cf94e17067dccc48639f9121 (plain)
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
//! ref: composer/vendor/symfony/console/Helper/TableRows.php

use crate::symfony::console::helper::table::Row;

/// @internal
///
/// In PHP this wraps a `\Closure` yielding a `\Traversable` of row groups. The generator
/// borrows the Table to lazily call `fillCells()`. For the Rust port we precompute the row
/// groups eagerly (see `Table::build_table_rows`) and store them here.
#[derive(Debug)]
pub struct TableRows {
    row_groups: Vec<Vec<Row>>,
}

impl TableRows {
    pub fn from_row_groups(row_groups: Vec<Vec<Row>>) -> Self {
        Self { row_groups }
    }

    pub fn get_iterator(&self) -> std::slice::Iter<'_, Vec<Row>> {
        self.row_groups.iter()
    }

    pub fn into_row_groups(self) -> Vec<Vec<Row>> {
        self.row_groups
    }
}

impl<'a> IntoIterator for &'a TableRows {
    type Item = &'a Vec<Row>;
    type IntoIter = std::slice::Iter<'a, Vec<Row>>;

    fn into_iter(self) -> Self::IntoIter {
        self.row_groups.iter()
    }
}

impl IntoIterator for TableRows {
    type Item = Vec<Row>;
    type IntoIter = std::vec::IntoIter<Vec<Row>>;

    fn into_iter(self) -> Self::IntoIter {
        self.row_groups.into_iter()
    }
}