Skip to content

Commit 53fda16

Browse files
committed
Better handling of empty tables without titles
1 parent 520359a commit 53fda16

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cli-table/src/row.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Row for RowStruct {
112112
}
113113

114114
/// Dimensions of a row
115-
#[derive(Debug, Clone, Eq, PartialEq)]
115+
#[derive(Debug, Default, Clone, Eq, PartialEq)]
116116
pub(crate) struct Dimension {
117117
/// Widths of each cell of row
118118
pub(crate) widths: Vec<usize>,

cli-table/src/table.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ impl TableStruct {
6666

6767
let row_dimension = match self.title {
6868
Some(ref title) => title.required_dimension(),
69-
None => self.rows[0].required_dimension(),
69+
None => {
70+
if self.rows.is_empty() {
71+
Default::default()
72+
} else {
73+
self.rows[0].required_dimension()
74+
}
75+
}
7076
};
7177

7278
let mut widths = row_dimension.widths;

0 commit comments

Comments
 (0)