Skip to content

Commit

Permalink
Update Dependencies and Refactor Code for zip Crate Breaking Changes (#…
Browse files Browse the repository at this point in the history
…245)

* chore: update compatible dependencies

* chore: update zip, quick-xml und hashbrown dependencies

- Upgraded dependencies:
  - `hashbrown` from 0.14.5 to 0.15.2
  - `quick-xml` from 0.36.2 to 0.37.1
  - `zip` from 1.1.4 to 2.2.1

Cells: replace `insert_unique_unchecked` with `insert`

- Updated the insertion logic in `Cells` to use `HashMap::insert` instead of the custom `insert_unique_unchecked`. This change ensures better safety and aligns with standard practices.

WriterManager: refactor to use mutable reference for `ZipWriter`

- Modified `WriterManager` to hold a mutable reference (`&mut`) to `ZipWriter` instead of consuming it directly.
- Adjusted the constructor and methods accordingly to reflect this change, improving flexibility and reducing unnecessary ownership transfers.
- This change was necessary due to breaking changes in the `zip` crate

Writer XLSX: fix `make_buffer` logic

- Refactored `make_buffer` to create and pass a mutable reference of `ZipWriter` to `WriterManager`.
- Simplified the logic for finalizing the archive by directly calling `arv.finish()` and returning the result.

These changes improve code safety, flexibility, and maintain compatibility with updated dependencies.

* refactor: remove `hashbrown` dependency

The `hashbrown` crate was unnecessary because `std::collections::HashMap` is already the default implementation in the standard library, based on `hashbrown`. This change removes the `hashbrown` dependency and updates all imports to use `std::collections::HashMap` instead, reducing the dependency surface and aligning with standard conventions.
  • Loading branch information
mxsrm authored Dec 2, 2024
1 parent 9185815 commit da7dc5e
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 34 deletions.
19 changes: 9 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ description = "umya-spreadsheet is a library written in pure Rust to read and wr
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aes = "0.8.3"
ahash = "0.8.7"
aes = "0.8.4"
ahash = "0.8.11"
base64 = "0.22.1"
byteorder = "1.5"
cbc = "0.1.2"
cfb = "0.10.0"
chrono = { version = "0.4.31", default-features = false, features = ["clock"] }
encoding_rs = "0.8.33"
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
encoding_rs = "0.8.35"
fancy-regex = "0.14.0"
getrandom = { version = "0.2.14" }
hashbrown = "0.14.5"
getrandom = { version = "0.2.15" }
hmac = "0.12.1"
html_parser = "0.7.0"
image = { version = "0.25.0", optional = true }
lazy_static = "1.4.0"
image = { version = "0.25.5", optional = true }
lazy_static = "1.5.0"
md-5 = "0.10.6"
regex = "1.11.1"
sha2 = "0.10.8"
thin-vec = "0.2.13"
thousands = "0.2.0"
quick-xml = { version = "0.36.2", features = ["serialize"] }
zip = { version = "1.1.4", default-features = false, features = ["deflate"] }
quick-xml = { version = "0.37.1", features = ["serialize"] }
zip = { version = "2.2.1", default-features = false, features = ["deflate"] }

[lib]
doctest = false
Expand Down
2 changes: 1 addition & 1 deletion src/helper/html.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use chrono::format;
use hashbrown::HashMap;
use html_parser::{Dom, Element, Node};
use std::collections::HashMap;
use structs::Color;
use structs::Font;
use structs::RichText;
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@

extern crate chrono;
extern crate fancy_regex;
extern crate hashbrown;
#[cfg(feature = "image")]
extern crate image;
extern crate md5;
Expand Down
2 changes: 1 addition & 1 deletion src/reader/xlsx/worksheet.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::driver::*;
use super::XlsxError;
use hashbrown::HashMap;
use quick_xml::events::Event;
use quick_xml::Reader;
use std::collections::HashMap;

use helper::formula::*;
use structs::office2010::excel::DataValidations as DataValidations2010;
Expand Down
2 changes: 1 addition & 1 deletion src/structs/cell.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use hashbrown::HashMap;
use helper::coordinate::*;
use helper::formula::*;
use helper::number_format::*;
Expand All @@ -7,6 +6,7 @@ use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::borrow::Cow;
use std::collections::HashMap;
use std::io::Cursor;
use std::sync::{Arc, RwLock};
use structs::CellFormula;
Expand Down
2 changes: 1 addition & 1 deletion src/structs/cell_formula.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use hashbrown::HashMap;
use helper::coordinate::*;
use helper::formula::*;
use quick_xml::de;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::collections::HashMap;
use std::io::Cursor;
use structs::BooleanValue;
use structs::CellFormulaValues;
Expand Down
4 changes: 2 additions & 2 deletions src/structs/cells.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::Cell;
use super::CellValue;
use super::Style;
use hashbrown::HashMap;
use helper::coordinate::*;
use helper::range::*;
use std::collections::HashMap;
use structs::Column;
use structs::Row;
use traits::AdjustmentCoordinate;
Expand Down Expand Up @@ -194,7 +194,7 @@ impl Cells {
let col_num = cell.get_coordinate().get_col_num();
let row_num = cell.get_coordinate().get_row_num();
let k = (row_num.to_owned(), col_num.to_owned());
self.map.insert_unique_unchecked(k, Box::new(cell));
self.map.insert(k, Box::new(cell));
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/structs/drawing/list_style.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// a:lstStyle
use super::EffectList;
use super::TextParagraphPropertiesType;
use hashbrown::HashMap;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::collections::HashMap;
use std::io::Cursor;
use writer::driver::*;

Expand Down
2 changes: 1 addition & 1 deletion src/structs/numbering_format.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use hashbrown::HashMap;
use md5::Digest;
use quick_xml::escape;
use quick_xml::events::BytesStart;
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::collections::HashMap;
use std::io::Cursor;
use writer::driver::*;

Expand Down
2 changes: 1 addition & 1 deletion src/structs/numbering_formats.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// numFmts
use super::NumberingFormat;
use super::Style;
use hashbrown::HashMap;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::collections::HashMap;
use std::io::Cursor;
use writer::driver::*;

Expand Down
2 changes: 1 addition & 1 deletion src/structs/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use super::SharedStringTable;
use super::Style;
use super::Stylesheet;
use super::UInt32Value;
use hashbrown::HashMap;
use helper::formula::*;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::collections::HashMap;
use std::io::Cursor;
use traits::AdjustmentValue;
use writer::driver::*;
Expand Down
2 changes: 1 addition & 1 deletion src/structs/rows.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hashbrown::HashMap;
use std::collections::HashMap;
use structs::Row;
use traits::AdjustmentValue;

Expand Down
2 changes: 1 addition & 1 deletion src/structs/shared_string_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use super::drawing::Theme;
use super::CellValue;
use super::SharedStringItem;
use drawing::charts::View3D;
use hashbrown::HashMap;
use helper::const_str::*;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::collections::HashMap;
use std::io::Cursor;
use thin_vec::ThinVec;
use writer::driver::*;
Expand Down
2 changes: 1 addition & 1 deletion src/structs/worksheet.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::traits;
use crate::StringValue;
use hashbrown::HashMap;
use helper::const_str::*;
use helper::coordinate::*;
use helper::range::*;
use reader::xlsx::worksheet::*;
use std::collections::HashMap;
use structs::drawing::spreadsheet::WorksheetDrawing;
use structs::office2010::excel::DataValidations as DataValidations2010;
use structs::raw::RawWorksheet;
Expand Down
10 changes: 5 additions & 5 deletions src/structs/writer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ use std::io::Cursor;
use structs::Spreadsheet;
use structs::XlsxError;
use writer::driver::*;
pub struct WriterManager<W: io::Seek + io::Write> {
pub struct WriterManager<'a, W: io::Seek + io::Write> {
files: Vec<String>,
arv: zip::ZipWriter<W>,
arv: &'a mut zip::ZipWriter<W>,
is_light: bool,
table_no: i32,
}

impl<W: io::Seek + io::Write> WriterManager<W> {
impl<'a, W: io::Seek + io::Write> WriterManager<'a, W> {
#[inline]
pub fn new(arv: zip::ZipWriter<W>) -> Self {
pub fn new(arv: &'a mut zip::ZipWriter<W>) -> Self {
WriterManager {
files: Vec::new(),
arv,
Expand Down Expand Up @@ -52,7 +52,7 @@ impl<W: io::Seek + io::Write> WriterManager<W> {
writer: Writer<Cursor<Vec<u8>>>,
) -> Result<(), XlsxError> {
if !self.check_file_exist(target) {
make_file_from_writer(target, &mut self.arv, writer, None, &self.is_light)?;
make_file_from_writer(target, self.arv, writer, None, &self.is_light)?;
self.files.push(target.to_string());
}
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/writer/xlsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fs;
use std::fs::File;
use std::io;
use std::io::Read;
use std::io::Write;
use std::path::Path;
use std::string::FromUtf8Error;
use structs::Spreadsheet;
Expand Down Expand Up @@ -36,8 +37,8 @@ mod worksheet;
mod worksheet_rels;

fn make_buffer(spreadsheet: &Spreadsheet, is_light: bool) -> Result<std::vec::Vec<u8>, XlsxError> {
let arv = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
let mut writer_manager = WriterManager::new(arv);
let mut arv = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
let mut writer_manager = WriterManager::new(&mut arv);
writer_manager.set_is_light(is_light);

// Add docProps App
Expand Down Expand Up @@ -170,8 +171,7 @@ fn make_buffer(spreadsheet: &Spreadsheet, is_light: bool) -> Result<std::vec::Ve
// Add Content_Types
content_types::write(spreadsheet, &mut writer_manager)?;

let result = writer_manager.get_arv_mut().finish()?;
Ok(result.into_inner())
Ok(arv.finish()?.into_inner())
}

/// write spreadsheet file to arbitrary writer.
Expand Down
2 changes: 1 addition & 1 deletion src/writer/xlsx/worksheet.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::driver::*;
use super::XlsxError;
use hashbrown::HashMap;
use helper::const_str::*;
use quick_xml::events::{BytesDecl, Event};
use quick_xml::Writer;
use std::collections::HashMap;
use std::io;
use std::sync::Arc;
use std::sync::RwLock;
Expand Down

0 comments on commit da7dc5e

Please sign in to comment.