-
Notifications
You must be signed in to change notification settings - Fork 537
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
Make Duration::seconds (and siblings) const fn #309
Comments
I don't think this is possible in current Rust - |
Yes, that's what I'm currently holding off on. Even once const fn is stable enough for chrono we'll need to think about how best to support them in a way that doesn't break backcompat too terribly. Chrono currently supports rust 1.13, but const fn is the strongest reason to upgrade to a new version that is upcoming. Obviously we'll update, but I'd like to keep things as compatible as possible, if that means adding some features or something else so that we can still work on old rustcs, I'm not sure. |
|
If anyone wants to create a PR for this behind something like an |
For the googlers that came here like me, it looks like the current blocker on this issue are const-panics (RFC) (issue) that are triggered when doing the .expect/panic-based bounds checking on the various Perhaps we can introduce variants that follow stdlib functions like checked_{mul,div,...}, and return an Since |
Still not good to go on with that change? |
With https://github.com/dtolnay/rustversion, there's a specific feature for making functions const conditionally on compiler versions since Edit: also found https://github.com/taiki-e/const_fn which is more specific macro and used by |
We now have const panics in rust 1.57 would it be possible to move this issue forward? |
I'm waiting for this. It seems this can be reviewed relatively easily. Can we merge the @msdrigg 's PR? Or are there other concerns? |
@quodlibetor does your offer still stand ? |
I'm open to merging something like this, provided it is made conditional on an opt-in feature flag (so that people who don't need this can still depend on the currently 1.32 MSRV). |
Fixed in #1337. |
Thanks ! |
This would allow to specify things like:
const THRESHOLD: Duration = Duration::seconds(3);
The text was updated successfully, but these errors were encountered: