Skip to content

Commit

Permalink
feat: add a method to return the cells of row instead of make it public
Browse files Browse the repository at this point in the history
  • Loading branch information
hulxv committed Sep 6, 2024
1 parent c4bde7a commit 8f497ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
pub cells: Vec<Cell>,
pub(crate) cells: Vec<Cell>,
pub(crate) max_height: Option<usize>,
}

Expand Down Expand Up @@ -80,6 +80,11 @@ impl Row {
pub fn cell_iter(&self) -> Iter<Cell> {
self.cells.iter()
}

/// Return the cells of this row.
pub fn cells(&self) -> Vec<Cell> {
self.cells.clone()
}
}

/// Create a Row from any `Into<Cells>`. \
Expand Down
6 changes: 3 additions & 3 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand Down Expand Up @@ -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}");
}
Expand Down

0 comments on commit 8f497ff

Please sign in to comment.