Skip to content

Commit

Permalink
Merge pull request #390 from lukapeschke/public-data-type-ref
Browse files Browse the repository at this point in the history
refactor: make `DataTypeRef` public and introduce a `DataTypeTrait` trait
  • Loading branch information
tafia authored Jan 16, 2024
2 parents 302ceef + 04c1e3e commit 212d373
Show file tree
Hide file tree
Showing 15 changed files with 612 additions and 363 deletions.
5 changes: 4 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

## Unreleased

- refactor: rename `DataType` enum to `Data` and `DataTypeRef` to `DataRef`
- feat: introduce a `DataType` trait implemented by both `Data` and `DataRef`.

## 0.23.1

- fix: `worksheet_formula` not returning all formula
Expand Down Expand Up @@ -146,7 +149,7 @@
- fix: xls - allow sectors ending after eof (truncate them!)

## 0.15.0
- feat: codepage/encoding_rs for codpage mapping
- feat: codepage/encoding_rs for codpage mapping

## 0.14.10
- fix: serde map do not stop at first empty value
Expand Down
20 changes: 10 additions & 10 deletions examples/excel_to_csv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use calamine::{open_workbook_auto, DataType, Range, Reader};
use calamine::{open_workbook_auto, Data, Range, Reader};
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
Expand Down Expand Up @@ -29,21 +29,21 @@ fn main() {
write_range(&mut dest, &range).unwrap();
}

fn write_range<W: Write>(dest: &mut W, range: &Range<DataType>) -> std::io::Result<()> {
fn write_range<W: Write>(dest: &mut W, range: &Range<Data>) -> std::io::Result<()> {
let n = range.get_size().1 - 1;
for r in range.rows() {
for (i, c) in r.iter().enumerate() {
match *c {
DataType::Empty => Ok(()),
DataType::String(ref s)
| DataType::DateTimeIso(ref s)
| DataType::DurationIso(ref s) => write!(dest, "{}", s),
DataType::Float(ref f) | DataType::DateTime(ref f) | DataType::Duration(ref f) => {
Data::Empty => Ok(()),
Data::String(ref s) | Data::DateTimeIso(ref s) | Data::DurationIso(ref s) => {
write!(dest, "{}", s)
}
Data::Float(ref f) | Data::DateTime(ref f) | Data::Duration(ref f) => {
write!(dest, "{}", f)
}
DataType::Int(ref i) => write!(dest, "{}", i),
DataType::Error(ref e) => write!(dest, "{:?}", e),
DataType::Bool(ref b) => write!(dest, "{}", b),
Data::Int(ref i) => write!(dest, "{}", i),
Data::Error(ref e) => write!(dest, "{:?}", e),
Data::Bool(ref b) => write!(dest, "{}", b),
}?;
if i != n {
write!(dest, ";")?;
Expand Down
4 changes: 2 additions & 2 deletions examples/search_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::PathBuf;

use calamine::{open_workbook_auto, DataType, Error, Reader};
use calamine::{open_workbook_auto, Data, Error, Reader};
use glob::{glob, GlobError, GlobResult};

#[derive(Debug)]
Expand Down Expand Up @@ -79,7 +79,7 @@ fn run(f: GlobResult) -> Result<(PathBuf, Option<usize>, usize), FileStatus> {
.rows()
.flat_map(|r| {
r.iter().filter(|c| {
if let DataType::Error(_) = **c {
if let Data::Error(_) = **c {
true
} else {
false
Expand Down
6 changes: 3 additions & 3 deletions src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::errors::Error;
use crate::vba::VbaProject;
use crate::{
open_workbook, open_workbook_from_rs, DataType, Metadata, Ods, Range, Reader, Xls, Xlsb, Xlsx,
open_workbook, open_workbook_from_rs, Data, Metadata, Ods, Range, Reader, Xls, Xlsb, Xlsx,
};
use std::borrow::Cow;
use std::fs::File;
Expand Down Expand Up @@ -105,7 +105,7 @@ where
}

/// Read worksheet data in corresponding worksheet path
fn worksheet_range(&mut self, name: &str) -> Result<Range<DataType>, Self::Error> {
fn worksheet_range(&mut self, name: &str) -> Result<Range<Data>, Self::Error> {
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),
Expand All @@ -124,7 +124,7 @@ where
}
}

fn worksheets(&mut self) -> Vec<(String, Range<DataType>)> {
fn worksheets(&mut self) -> Vec<(String, Range<Data>)> {
match *self {
Sheets::Xls(ref mut e) => e.worksheets(),
Sheets::Xlsx(ref mut e) => e.worksheets(),
Expand Down
Loading

0 comments on commit 212d373

Please sign in to comment.