Extract method for table widths total

This commit is contained in:
Benjamin Sago 2017-07-03 20:21:33 +01:00
parent 1b58f012e0
commit fec4c45301
2 changed files with 7 additions and 8 deletions

View File

@ -61,7 +61,6 @@
use std::io::{Write, Error as IOError, Result as IOResult};
use std::ops::Add;
use std::path::PathBuf;
use std::vec::IntoIter as VecIntoIter;
@ -320,7 +319,7 @@ impl<'a> Render<'a> {
pub fn iterate_with_table(&'a self, table: Table<'a>, rows: Vec<Row>) -> TableIter<'a> {
TableIter {
tree_trunk: TreeTrunk::default(),
total_width: table.columns_count() + table.widths().iter().fold(0, Add::add),
total_width: table.widths().total(),
table: table,
inner: rows.into_iter(),
colours: self.colours,

View File

@ -90,12 +90,8 @@ impl<'a, 'f> Table<'a> {
Table { columns, colours, env, widths }
}
pub fn columns_count(&self) -> usize {
self.columns.len()
}
pub fn widths(&self) -> &[usize] {
&*self.widths
pub fn widths(&self) -> &TableWidths {
&self.widths
}
pub fn header_row(&self) -> Row {
@ -185,4 +181,8 @@ impl TableWidths {
*old_width = max(*old_width, *cell.width);
}
}
pub fn total(&self) -> usize {
self.0.len() + self.0.iter().sum::<usize>()
}
}