Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make DataTypeRef public and introduce a DataTypeTrait trait #390

Merged
merged 7 commits into from
Jan 16, 2024

Conversation

lukapeschke
Copy link
Contributor

Hello there, I recently discovered DataTypeRef in the changelog, really nice addition!

However, it is not publicly available through the API, so I figured I wanted to make it public. I then realised that it would be convenient to have a DataType trait, in order to allow for generics. I was thinking about something like this:

use calamine::{CellType, DataTypeTrait, Range};

fn do_stuff_on_data_range<DT: CellType + DataTypeTrait + Debug>(data_range: &Range<DT>) {
    todo!()
}

Is this something you would be interested in ? If yes, we can probably find better naming for the trait and maybe a cleaner API ?

Cheers!

@lukapeschke
Copy link
Contributor Author

@tafia this is an example of what this would allow us to do on the fastexcel side: https://github.com/ToucanToco/fastexcel/pull/147/files#diff-b918afe42fb2f27a4f1d2295adf56664cdf9f5f089202d0ddf9a48245e15a47bR42 🙂

src/datatype.rs Outdated
Comment on lines 62 to 65
#[cfg(feature = "dates")]
fn is_duration(&self) -> bool {
matches!(*self, DataType::Duration(_))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this (and similar methods) under the dates feature? This feature is needed only for converting excel date to chrono

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the as_{datetime,duration} are under the dates feature as well, so it was mainly for consistency.

@tafia
Copy link
Owner

tafia commented Jan 12, 2024

Thanks for the PR.
I am not a fan of DataTypeTrait name. I'd rather have a name without Trait in it. Maybe a simpler Data (really opened to suggestions).

@lukapeschke
Copy link
Contributor Author

I am not a fan of DataTypeTrait name. I'd rather have a name without Trait in it. Maybe a simpler Data (really opened to suggestions).

Maybe DataType as the trait name, and rename the DataType enum to DataTypeOwned ?

Apart from that, you wouldn't be opposed to having such a trait an making DataTypeRef public ?

@tafia
Copy link
Owner

tafia commented Jan 13, 2024

No I am definitely not opposed to having such trait and exposing the Ref variant.

How about DataType for the trait, and Data/DataRef for the enums. The rationale is

  • no Trait in name
  • smaller names if used more frequently (I believe that Data will still be used the most)
  • not a super fan of Owned variant.

An alternative? would be to use a Cow with the borrowed variant the owned one and the ref variant the Ref one.

@lukapeschke
Copy link
Contributor Author

DataType and Data/DataRef sounds good 👍 I'll do the change asap

Rename the following:

* DataTypeTrait -> DataType
* DataType -> Data
* DataTypeRef -> DataRef

Signed-off-by: Luka Peschke <[email protected]>
Signed-off-by: Luka Peschke <[email protected]>
Signed-off-by: Luka Peschke <[email protected]>
@tafia
Copy link
Owner

tafia commented Jan 15, 2024

Great.
Can you please update the Changelog, as it is a breaking change, to be sure I won't forget to put it.
Thanks!

@lukapeschke
Copy link
Contributor Author

@tafia I udapted the changelog in e2fe7f9 , do you want me to add something else ?

@tafia tafia merged commit 212d373 into tafia:master Jan 16, 2024
4 checks passed
@tafia
Copy link
Owner

tafia commented Jan 16, 2024

Awesome! Thanks!

@lukapeschke
Copy link
Contributor Author

Thank you for the quick reviews!

@lukapeschke lukapeschke deleted the public-data-type-ref branch January 16, 2024 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants