Преглед изворни кода

Extract method for table widths total

Benjamin Sago пре 8 година
родитељ
комит
fec4c45301
2 измењених фајлова са 7 додато и 8 уклоњено
  1. 1 2
      src/output/details.rs
  2. 6 6
      src/output/table.rs

+ 1 - 2
src/output/details.rs

@@ -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,

+ 6 - 6
src/output/table.rs

@@ -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>()
+    }
 }