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

Consts for locales' date, time and datetime #475

Closed
cecton opened this issue Aug 28, 2020 · 2 comments
Closed

Consts for locales' date, time and datetime #475

cecton opened this issue Aug 28, 2020 · 2 comments

Comments

@cecton
Copy link
Contributor

cecton commented Aug 28, 2020

Following our conversation on #453 (comment)

I made a few attempts since we talk about it but it is utterly complicated and will be a pain to maintain (if achievable at all).

  • Using a build.rs you can't just use types inside the crate itself and I need them to parse the formats
  • Slitting the crate could work in modern versions of Rust but there are compatibility issues with Rust v1.13, most notably with the include! that behaves a bit differently (ofc we don't need locales in 1.13 but I still needed to some includes! to avoid code duplication)
  • I saw yesterday that we can do more with const fn which makes it a great candidate but there are still some barriers to make it work: you can't mutate yet but we need it for the Iterator. (I think we would still need a build.rs to generate the code but it will be way less problematic.)

I don't have a solution for now that wouldn't involve huge changes on chrono. We should keep this issue open so if there are new changes in the futures we might be able to find a good solution.

@rodrimati1992
Copy link

You can do mutation of local variables that you get by value, so you can do something Iterator-like by returning the mutated iterator along with the next value.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=eb47297dea5d81ab8ab65edd5cdbcbda
This isn't very ergonomic, though.

@pitdicker
Copy link
Collaborator

Since #1152 we no longer allocate Vec's for the localized formatting strings, but just switch to parsing one if we encounter the corresponding specifier.

The idea to pre-parse all format strings into slices of [Item]'s seems less ideal to me: the size of an Item is 24 bytes, while a formatting specifier may only need two bytes (like %Y). And a literal like - needs only one byte, while Item::Literal needs 24 bytes and a place to but the slice with "-". So that would blow up the size of the binary unnecessary.

Closing as completed.

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

No branches or pull requests

3 participants