diff --git a/src/row.rs b/src/row.rs index 14a6238..fc54df8 100644 --- a/src/row.rs +++ b/src/row.rs @@ -11,7 +11,7 @@ pub struct Row { /// Index of the row. /// This will be set as soon as the row is added to the table. pub(crate) index: Option, - pub cells: Vec, + pub(crate) cells: Vec, pub(crate) max_height: Option, } @@ -80,6 +80,11 @@ impl Row { pub fn cell_iter(&self) -> Iter { self.cells.iter() } + + /// Return the cells of this row. + pub fn cells(&self) -> Vec { + self.cells.clone() + } } /// Create a Row from any `Into`. \ diff --git a/src/table.rs b/src/table.rs index 34e8bd1..13400d1 100644 --- a/src/table.rs +++ b/src/table.rs @@ -259,7 +259,7 @@ impl Table { /// .add_row(vec![Cell::new("Al-khwarizmi")]); /// /// // Sort the rows in descending order based on the first column - /// table.sort_rows(|a, b| b.cells[0].cmp(&a.cells[0])); + /// table.sort_rows(|a, b| b.cells()[0].cmp(&a.cells()[0])); /// /// // Print the table after sorting /// println!("Sort in descending order:"); @@ -959,11 +959,11 @@ mod tests { .add_row(vec![Cell::new("Neil Armstrong")]) .add_row(vec![Cell::new("Hassan Ibn Al-haitham")]) .add_row(vec![Cell::new("Al-khwarizmi")]); - table.sort_rows(|a, b| b.cells[0].cmp(&a.cells[0])); + table.sort_rows(|a, b| b.cells()[0].cmp(&a.cells()[0])); println!("\nsort in descending order:\n"); println!("{table}"); - table.sort_rows(|a, b| a.cells[0].cmp(&b.cells[0])); + table.sort_rows(|a, b| a.cells()[0].cmp(&b.cells()[0])); println!("\nsort in ascending order:\n"); println!("{table}"); }