term: Replace manual Extend impl for Table

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2025-09-07 12:39:32 +02:00
parent f00d1d6743
commit 11fc98c9c9
No known key found for this signature in database
1 changed files with 14 additions and 6 deletions

View File

@ -191,12 +191,6 @@ impl<const W: usize, T: Cell> Table<W, T> {
self.rows.push(Row::Header(row)); 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 { pub fn is_empty(&self) -> bool {
!self.rows.iter().any(|r| matches!(r, Row::Data { .. })) !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)] #[cfg(test)]
mod test { mod test {
use crate::Element; use crate::Element;