Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
term/table: Add impl FromIterator for Table
Matthias Beyer committed 8 months ago
commit 41a742ed9be97ca9d4279b4e34d8006f5675d34e
parent ff021d58897db7b927f1b4ba20959be013137961
1 file changed +13 -0
modified crates/radicle-term/src/table.rs
@@ -78,6 +78,19 @@ impl<const W: usize, T> Default for Table<W, T> {
    }
}

+
impl<const W: usize, T: Cell> FromIterator<[T; W]> for Table<W, T> {
+
    fn from_iter<I: IntoIterator<Item = [T; W]>>(iter: I) -> Self {
+
        let mut table = Self::default();
+
        table.rows.extend(iter.into_iter().map(|row| {
+
            for (i, cell) in row.iter().enumerate() {
+
                table.widths[i] = table.widths[i].max(cell.width());
+
            }
+
            Row::Data(row)
+
        }));
+
        table
+
    }
+
}
+

impl<const W: usize, T: Cell + fmt::Debug + Send + Sync> Element for Table<W, T>
where
    T::Padded: Into<Line>,