Skip to content

Commit 61bcc6d

Browse files
authored
Fix crash when there is no header and no data (#78)
1 parent c2d3782 commit 61bcc6d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/utils.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ pub fn create_list_table<T: Entity>(
5050
}
5151
}
5252
}
53-
let id_column = table.get_column_mut(0).unwrap();
54-
id_column.set_constraint(ColumnConstraint::MinWidth(ID_COLUMN_WIDTH));
53+
if let Some(id_column) = table.get_column_mut(0) {
54+
id_column.set_constraint(ColumnConstraint::MinWidth(ID_COLUMN_WIDTH));
55+
}
5556
table
5657
}
5758

@@ -555,6 +556,15 @@ mod tests {
555556
);
556557
}
557558

559+
#[test]
560+
fn test_create_list_table_no_header_no_data() {
561+
let data: Vec<Patient> = vec![];
562+
assert_eq!(
563+
format_table(create_list_table(data, None, &PATIENTS_LIST_DICOM_TAGS)),
564+
""
565+
);
566+
}
567+
558568
#[test]
559569
fn test_create_show_table_patient() {
560570
let patient = Patient {

0 commit comments

Comments
 (0)