Skip to content

Commit

Permalink
refactor: use mutable ref
Browse files Browse the repository at this point in the history
  • Loading branch information
PrettyWood committed Oct 5, 2024
1 parent dd33174 commit 65d4c2d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ where
fn set_options(&mut self, options: Self::Options);

/// Set options and return the reader
fn with_options(mut self, options: Self::Options) -> Self {
fn with_options(&mut self, options: Self::Options) -> &mut Self {
self.set_options(options);
self
}
Expand Down
8 changes: 0 additions & 8 deletions src/xlsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,14 +866,6 @@ impl<RS: Read + Seek> Xlsx<RS> {
}
}

impl<RS> Xlsx<RS> {
/// Set reader options
pub fn with_options(mut self, options: XlsxOptions) -> Self {
self.options = options;
self
}
}

impl<RS: Read + Seek> Reader<RS> for Xlsx<RS> {
type Error = XlsxError;
type Options = XlsxOptions;
Expand Down
21 changes: 17 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ fn test_header_row_xlsx(
#[case] expected_first_row: &[Data],
#[case] expected_total_cells: usize,
) {
let excel: Xlsx<_> = wb(fixture_path);
let mut excel: Xlsx<_> = wb(fixture_path);
assert_eq!(
excel.sheets_metadata(),
&[Sheet {
Expand All @@ -1833,7 +1833,20 @@ fn test_header_row_xlsx(
assert_eq!(range.cells().count(), expected_total_cells);
}

#[rstest]
#[test]
fn test_read_twice_with_different_header_rows() {
let mut xlsx: Xlsx<_> = wb("any_sheets.xlsx");
let _ = xlsx
.with_options(XlsxOptions::default().with_header_row(2))
.worksheet_range("Visible")
.unwrap();
let _ = xlsx
.with_options(XlsxOptions::default().with_header_row(1))
.worksheet_range("Visible")
.unwrap();
}

#[test]
fn test_header_row_xlsb() {
let mut xlsb: Xlsb<_> = wb("date.xlsb");
assert_eq!(
Expand Down Expand Up @@ -1877,7 +1890,7 @@ fn test_header_row_xlsb() {
assert_eq!(range.rows().next().unwrap(), &second_line);
}

#[rstest]
#[test]
fn test_header_row_xls() {
let mut xls: Xls<_> = wb("date.xls");
assert_eq!(
Expand Down Expand Up @@ -1921,7 +1934,7 @@ fn test_header_row_xls() {
assert_eq!(range.rows().next().unwrap(), &second_line);
}

#[rstest]
#[test]
fn test_header_row_ods() {
let mut ods: Ods<_> = wb("date.ods");
assert_eq!(
Expand Down

0 comments on commit 65d4c2d

Please sign in to comment.