informationsea / xlsxwriter-rs

Excel file writer for Rust
https://crates.io/crates/xlsxwriter
Apache License 2.0
265 stars 44 forks source link

Rusty enums in DataValidation #45

Closed 2ndDerivative closed 1 year ago

2ndDerivative commented 1 year ago

Linking to issue #44 I made a first proposal to more closely align the abilities of Rusts type system to put away the mutable structure of Data Validation objects and make unnecessary changes to them impossible.

The "None"-Type of Data validation is not used since it has no representation (that I know of) in the Excel spreadsheet options, so I removed it. I fit all the possible enumerations and/or parallel options like the three tabs of the data validation settings (Settings, Input Message, Error Alert) into their respective part of the Data validation object and made the latter two unusable without setting an actual data validation setting (the same way Excel doesn't represent the other tabs when "Any" is chosen in the validation settings)

Arguments

the new API would have DataValidation take three arguments, two of which are optional:

There still has to be some work done on making the different number options (equal, not equal, greater than, less than etc...) more usable, but it is already less messy than the mutable state weirdness that was used before, and which was not very "oxidized"

Please consider this proposal and tell me if you have any tips or feedback. I will continue some work on this to put it into better shape, but I'd love for the compiler to be able to help you in this better.

Another idea to make this less yanky with nested structs would be to pull the three DataValidation::new()-arguments directly into the data_validation_cell() and data_validation_range() functions

2ndDerivative commented 1 year ago

Is this going to be considered? And if not, is there a way I can make it acceptable? @informationsea

informationsea commented 1 year ago

Thank you for your pull request.