Skip to content

Commit

Permalink
refactor: switch to matching on reference
Browse files Browse the repository at this point in the history
  • Loading branch information
PrettyWood committed Oct 4, 2024
1 parent ff35b2c commit dd33174
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,18 @@ where
}

fn set_options(&mut self, options: Self::Options) {
match *self {
Sheets::Xls(ref mut e) => match options {
AutoReaderOptions::Xls(opts) => e.set_options(opts),
_ => unreachable!(),
},
Sheets::Xlsx(ref mut e) => match options {
AutoReaderOptions::Xlsx(opts) => e.set_options(opts),
_ => unreachable!(),
},
Sheets::Xlsb(ref mut e) => match options {
AutoReaderOptions::Xlsb(opts) => e.set_options(opts),
_ => unreachable!(),
},
Sheets::Ods(ref mut e) => match options {
AutoReaderOptions::Ods(opts) => e.set_options(opts),
_ => unreachable!(),
},
match (self, options) {
(Sheets::Xls(ref mut e), AutoReaderOptions::Xls(opts)) => e.set_options(opts),
(Sheets::Xlsx(ref mut e), AutoReaderOptions::Xlsx(opts)) => e.set_options(opts),
(Sheets::Xlsb(ref mut e), AutoReaderOptions::Xlsb(opts)) => e.set_options(opts),
(Sheets::Ods(ref mut e), AutoReaderOptions::Ods(opts)) => e.set_options(opts),
_ => unreachable!(),
}
}

/// Gets `VbaProject`
fn vba_project(&mut self) -> Option<Result<Cow<'_, VbaProject>, Self::Error>> {
match *self {
match self {
Sheets::Xls(ref mut e) => e.vba_project().map(|vba| vba.map_err(Error::Xls)),
Sheets::Xlsx(ref mut e) => e.vba_project().map(|vba| vba.map_err(Error::Xlsx)),
Sheets::Xlsb(ref mut e) => e.vba_project().map(|vba| vba.map_err(Error::Xlsb)),
Expand All @@ -138,7 +127,7 @@ where

/// Initialize
fn metadata(&self) -> &Metadata {
match *self {
match self {
Sheets::Xls(ref e) => e.metadata(),
Sheets::Xlsx(ref e) => e.metadata(),
Sheets::Xlsb(ref e) => e.metadata(),
Expand All @@ -148,7 +137,7 @@ where

/// Read worksheet data in corresponding worksheet path
fn worksheet_range(&mut self, name: &str) -> Result<Range<Data>, Self::Error> {
match *self {
match self {
Sheets::Xls(ref mut e) => e.worksheet_range(name).map_err(Error::Xls),
Sheets::Xlsx(ref mut e) => e.worksheet_range(name).map_err(Error::Xlsx),
Sheets::Xlsb(ref mut e) => e.worksheet_range(name).map_err(Error::Xlsb),
Expand All @@ -158,7 +147,7 @@ where

/// Read worksheet formula in corresponding worksheet path
fn worksheet_formula(&mut self, name: &str) -> Result<Range<String>, Self::Error> {
match *self {
match self {
Sheets::Xls(ref mut e) => e.worksheet_formula(name).map_err(Error::Xls),
Sheets::Xlsx(ref mut e) => e.worksheet_formula(name).map_err(Error::Xlsx),
Sheets::Xlsb(ref mut e) => e.worksheet_formula(name).map_err(Error::Xlsb),
Expand All @@ -167,7 +156,7 @@ where
}

fn worksheets(&mut self) -> Vec<(String, Range<Data>)> {
match *self {
match self {
Sheets::Xls(ref mut e) => e.worksheets(),
Sheets::Xlsx(ref mut e) => e.worksheets(),
Sheets::Xlsb(ref mut e) => e.worksheets(),
Expand All @@ -177,7 +166,7 @@ where

#[cfg(feature = "picture")]
fn pictures(&self) -> Option<Vec<(String, Vec<u8>)>> {
match *self {
match self {
Sheets::Xls(ref e) => e.pictures(),
Sheets::Xlsx(ref e) => e.pictures(),
Sheets::Xlsb(ref e) => e.pictures(),
Expand All @@ -194,7 +183,7 @@ where
&'a mut self,
name: &str,
) -> Result<Range<DataRef<'a>>, Self::Error> {
match *self {
match self {
Sheets::Xlsx(ref mut e) => e.worksheet_range_ref(name).map_err(Error::Xlsx),
Sheets::Xlsb(ref mut e) => e.worksheet_range_ref(name).map_err(Error::Xlsb),
Sheets::Xls(_) => unimplemented!(),
Expand Down

0 comments on commit dd33174

Please sign in to comment.