Skip to content

Commit 0d772d1

Browse files
authored
Merge pull request #500 from sbruton/master
fix for zip v2.6 semver violation
2 parents ce523d9 + 0e11324 commit 0d772d1

File tree

6 files changed

+85
-38
lines changed

6 files changed

+85
-38
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fast-float2 = "0.2"
2222
log = "0.4"
2323
serde = "1.0"
2424
quick-xml = { version = "0.37", features = ["encoding"] }
25-
zip = { version = "~2.5.0", default-features = false, features = ["deflate"] }
25+
zip = { version = "2.6", default-features = false, features = ["deflate"] }
2626
chrono = { version = "0.4", features = [
2727
"serde",
2828
], optional = true, default-features = false }

src/ods.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::marker::PhantomData;
2121

2222
const MIMETYPE: &[u8] = b"application/vnd.oasis.opendocument.spreadsheet";
2323

24-
type OdsReader<'a> = XmlReader<BufReader<ZipFile<'a>>>;
24+
type OdsReader<'a, RS> = XmlReader<BufReader<ZipFile<'a, RS>>>;
2525

2626
/// An enum for ods specific errors
2727
#[derive(Debug)]
@@ -387,7 +387,10 @@ fn parse_content<RS: Read + Seek>(mut zip: ZipArchive<RS>) -> Result<Content, Od
387387
})
388388
}
389389

390-
fn read_table(reader: &mut OdsReader<'_>) -> Result<(Range<Data>, Range<String>), OdsError> {
390+
fn read_table<RS>(reader: &mut OdsReader<'_, RS>) -> Result<(Range<Data>, Range<String>), OdsError>
391+
where
392+
RS: Read + Seek,
393+
{
391394
let mut cells = Vec::new();
392395
let mut rows_repeats = Vec::new();
393396
let mut formulas = Vec::new();
@@ -531,13 +534,16 @@ fn get_range<T: Default + Clone + PartialEq>(
531534
}
532535
}
533536

534-
fn read_row(
535-
reader: &mut OdsReader<'_>,
537+
fn read_row<RS>(
538+
reader: &mut OdsReader<'_, RS>,
536539
row_buf: &mut Vec<u8>,
537540
cell_buf: &mut Vec<u8>,
538541
cells: &mut Vec<Data>,
539542
formulas: &mut Vec<String>,
540-
) -> Result<(), OdsError> {
543+
) -> Result<(), OdsError>
544+
where
545+
RS: Read + Seek,
546+
{
541547
let mut empty_col_repeats = 0;
542548
loop {
543549
row_buf.clear();
@@ -595,11 +601,14 @@ fn read_row(
595601
/// Converts table-cell element into a `Data`
596602
///
597603
/// ODF 1.2-19.385
598-
fn get_datatype(
599-
reader: &mut OdsReader<'_>,
604+
fn get_datatype<RS>(
605+
reader: &mut OdsReader<'_, RS>,
600606
atts: Attributes<'_>,
601607
buf: &mut Vec<u8>,
602-
) -> Result<(Data, String, bool), OdsError> {
608+
) -> Result<(Data, String, bool), OdsError>
609+
where
610+
RS: Read + Seek,
611+
{
603612
let mut is_string = false;
604613
let mut is_value_set = false;
605614
let mut val = Data::Empty;
@@ -697,7 +706,12 @@ fn get_datatype(
697706
}
698707
}
699708

700-
fn read_named_expressions(reader: &mut OdsReader<'_>) -> Result<Vec<(String, String)>, OdsError> {
709+
fn read_named_expressions<RS>(
710+
reader: &mut OdsReader<'_, RS>,
711+
) -> Result<Vec<(String, String)>, OdsError>
712+
where
713+
RS: Read + Seek,
714+
{
701715
let mut defined_names = Vec::new();
702716
let mut buf = Vec::with_capacity(512);
703717
loop {

src/xlsb/cells_reader.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::io::{Read, Seek};
2+
13
use crate::{
24
datatype::DataRef,
35
formats::{format_excel_f64_ref, CellFormat},
@@ -8,8 +10,11 @@ use crate::{
810
use super::{cell_format, parse_formula, wide_str, RecordIter};
911

1012
/// A cells reader for xlsb files
11-
pub struct XlsbCellsReader<'a> {
12-
iter: RecordIter<'a>,
13+
pub struct XlsbCellsReader<'a, RS>
14+
where
15+
RS: Read + Seek,
16+
{
17+
iter: RecordIter<'a, RS>,
1318
formats: &'a [CellFormat],
1419
strings: &'a [String],
1520
extern_sheets: &'a [String],
@@ -21,9 +26,12 @@ pub struct XlsbCellsReader<'a> {
2126
buf: Vec<u8>,
2227
}
2328

24-
impl<'a> XlsbCellsReader<'a> {
29+
impl<'a, RS> XlsbCellsReader<'a, RS>
30+
where
31+
RS: Read + Seek,
32+
{
2533
pub(crate) fn new(
26-
mut iter: RecordIter<'a>,
34+
mut iter: RecordIter<'a, RS>,
2735
formats: &'a [CellFormat],
2836
strings: &'a [String],
2937
extern_sheets: &'a [String],

src/xlsb/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl<RS: Read + Seek> Xlsb<RS> {
408408
pub fn worksheet_cells_reader<'a>(
409409
&'a mut self,
410410
name: &str,
411-
) -> Result<XlsbCellsReader<'a>, XlsbError> {
411+
) -> Result<XlsbCellsReader<'a, RS>, XlsbError> {
412412
let path = match self.sheets.iter().find(|&(n, _)| n == name) {
413413
Some((_, path)) => path.clone(),
414414
None => return Err(XlsbError::WorksheetNotFound(name.into())),
@@ -608,16 +608,19 @@ impl<RS: Read + Seek> ReaderRef<RS> for Xlsb<RS> {
608608
}
609609
}
610610

611-
pub(crate) struct RecordIter<'a> {
611+
pub(crate) struct RecordIter<'a, RS>
612+
where
613+
RS: Read + Seek,
614+
{
612615
b: [u8; 1],
613-
r: BufReader<ZipFile<'a>>,
616+
r: BufReader<ZipFile<'a, RS>>,
614617
}
615618

616-
impl<'a> RecordIter<'a> {
617-
fn from_zip<RS: Read + Seek>(
618-
zip: &'a mut ZipArchive<RS>,
619-
path: &str,
620-
) -> Result<RecordIter<'a>, XlsbError> {
619+
impl<'a, RS> RecordIter<'a, RS>
620+
where
621+
RS: Read + Seek,
622+
{
623+
fn from_zip(zip: &'a mut ZipArchive<RS>, path: &str) -> Result<RecordIter<'a, RS>, XlsbError> {
621624
match zip.by_name(path) {
622625
Ok(f) => Ok(RecordIter {
623626
r: BufReader::new(f),

src/xlsx/cells_reader.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ use quick_xml::{
22
events::{attributes::Attribute, BytesStart, Event},
33
name::QName,
44
};
5-
use std::{borrow::Borrow, collections::HashMap};
5+
use std::{
6+
borrow::Borrow,
7+
collections::HashMap,
8+
io::{Read, Seek},
9+
};
610

711
use super::{
812
get_attribute, get_dimension, get_row, get_row_column, read_string, replace_cell_names,
@@ -17,8 +21,11 @@ use crate::{
1721
type FormulaMap = HashMap<(u32, u32), (i64, i64)>;
1822

1923
/// An xlsx Cell Iterator
20-
pub struct XlsxCellReader<'a> {
21-
xml: XlReader<'a>,
24+
pub struct XlsxCellReader<'a, RS>
25+
where
26+
RS: Read + Seek,
27+
{
28+
xml: XlReader<'a, RS>,
2229
strings: &'a [String],
2330
formats: &'a [CellFormat],
2431
is_1904: bool,
@@ -30,9 +37,12 @@ pub struct XlsxCellReader<'a> {
3037
formulas: Vec<Option<(String, FormulaMap)>>,
3138
}
3239

33-
impl<'a> XlsxCellReader<'a> {
40+
impl<'a, RS> XlsxCellReader<'a, RS>
41+
where
42+
RS: Read + Seek,
43+
{
3444
pub fn new(
35-
mut xml: XlReader<'a>,
45+
mut xml: XlReader<'a, RS>,
3646
strings: &'a [String],
3747
formats: &'a [CellFormat],
3848
is_1904: bool,
@@ -281,14 +291,17 @@ impl<'a> XlsxCellReader<'a> {
281291
}
282292
}
283293

284-
fn read_value<'s>(
294+
fn read_value<'s, RS>(
285295
strings: &'s [String],
286296
formats: &[CellFormat],
287297
is_1904: bool,
288-
xml: &mut XlReader<'_>,
298+
xml: &mut XlReader<'_, RS>,
289299
e: &BytesStart<'_>,
290300
c_element: &BytesStart<'_>,
291-
) -> Result<DataRef<'s>, XlsxError> {
301+
) -> Result<DataRef<'s>, XlsxError>
302+
where
303+
RS: Read + Seek,
304+
{
292305
Ok(match e.local_name().as_ref() {
293306
b"is" => {
294307
// inlineStr
@@ -385,7 +398,10 @@ fn read_v<'s>(
385398
}
386399
}
387400

388-
fn read_formula(xml: &mut XlReader, e: &BytesStart) -> Result<Option<String>, XlsxError> {
401+
fn read_formula<RS>(xml: &mut XlReader<RS>, e: &BytesStart) -> Result<Option<String>, XlsxError>
402+
where
403+
RS: Read + Seek,
404+
{
389405
match e.local_name().as_ref() {
390406
b"is" | b"v" => {
391407
xml.read_to_end_into(e.name(), &mut Vec::new())?;

src/xlsx/mod.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
};
2424
pub use cells_reader::XlsxCellReader;
2525

26-
pub(crate) type XlReader<'a> = XmlReader<BufReader<ZipFile<'a>>>;
26+
pub(crate) type XlReader<'a, RS> = XmlReader<BufReader<ZipFile<'a, RS>>>;
2727

2828
/// Maximum number of rows allowed in an xlsx file
2929
pub const MAX_ROWS: u32 = 1_048_576;
@@ -905,7 +905,7 @@ impl<RS: Read + Seek> Xlsx<RS> {
905905
pub fn worksheet_cells_reader<'a>(
906906
&'a mut self,
907907
name: &str,
908-
) -> Result<XlsxCellReader<'a>, XlsxError> {
908+
) -> Result<XlsxCellReader<'a, RS>, XlsxError> {
909909
let (_, path) = self
910910
.sheets
911911
.iter()
@@ -1095,7 +1095,7 @@ impl<RS: Read + Seek> ReaderRef<RS> for Xlsx<RS> {
10951095
fn xml_reader<'a, RS: Read + Seek>(
10961096
zip: &'a mut ZipArchive<RS>,
10971097
path: &str,
1098-
) -> Option<Result<XlReader<'a>, XlsxError>> {
1098+
) -> Option<Result<XlReader<'a, RS>, XlsxError>> {
10991099
let actual_path = zip
11001100
.file_names()
11011101
.find(|n| n.eq_ignore_ascii_case(path))?
@@ -1236,10 +1236,13 @@ fn get_row_and_optional_column(range: &[u8]) -> Result<(u32, Option<u32>), XlsxE
12361236
}
12371237

12381238
/// attempts to read either a simple or richtext string
1239-
pub(crate) fn read_string(
1240-
xml: &mut XlReader<'_>,
1239+
pub(crate) fn read_string<RS>(
1240+
xml: &mut XlReader<'_, RS>,
12411241
closing: QName,
1242-
) -> Result<Option<String>, XlsxError> {
1242+
) -> Result<Option<String>, XlsxError>
1243+
where
1244+
RS: Read + Seek,
1245+
{
12431246
let mut buf = Vec::with_capacity(1024);
12441247
let mut val_buf = Vec::with_capacity(1024);
12451248
let mut rich_buffer: Option<String> = None;
@@ -1301,7 +1304,10 @@ fn check_for_password_protected<RS: Read + Seek>(reader: &mut RS) -> Result<(),
13011304
Ok(())
13021305
}
13031306

1304-
fn read_merge_cells(xml: &mut XlReader<'_>) -> Result<Vec<Dimensions>, XlsxError> {
1307+
fn read_merge_cells<RS>(xml: &mut XlReader<'_, RS>) -> Result<Vec<Dimensions>, XlsxError>
1308+
where
1309+
RS: Read + Seek,
1310+
{
13051311
let mut merge_cells = Vec::new();
13061312

13071313
loop {

0 commit comments

Comments
 (0)