Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
term: Replace manual Extend impl for Table
Merged did:key:z6MkwcUR...q1kL opened 7 months ago

There’s nothing more to say here.

1 file changed +14 -6 f00d1d67 11fc98c9
modified crates/radicle-term/src/table.rs
@@ -191,12 +191,6 @@ impl<const W: usize, T: Cell> Table<W, T> {
        self.rows.push(Row::Header(row));
    }

-
    pub fn extend(&mut self, rows: impl IntoIterator<Item = [T; W]>) {
-
        for row in rows.into_iter() {
-
            self.push(row);
-
        }
-
    }
-

    pub fn is_empty(&self) -> bool {
        !self.rows.iter().any(|r| matches!(r, Row::Data { .. }))
    }
@@ -225,6 +219,20 @@ impl<const W: usize, T: Cell> Table<W, T> {
    }
}

+
impl<const W: usize, T: Cell> Extend<[T; W]> for Table<W, T> {
+
    fn extend<I>(&mut self, iter: I)
+
    where
+
        I: IntoIterator<Item = [T; W]>,
+
    {
+
        self.rows.extend(iter.into_iter().map(|row| {
+
            for (i, cell) in row.iter().enumerate() {
+
                self.widths[i] = self.widths[i].max(cell.width());
+
            }
+
            Row::Data(row)
+
        }));
+
    }
+
}
+

#[cfg(test)]
mod test {
    use crate::Element;