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

Use std::time::Duration instead of time::duration::Duration for max-age #208

Closed
laplus-sadness opened this issue Jan 21, 2023 · 1 comment

Comments

@laplus-sadness
Copy link

Hello. I like using axum to design some stuff, but their implementation of cookies (axum-extra::extract::cookies) doesn't automatically re-export time.

I know that I could simply ask them to export time or include it myself, but considering that all the uses of max-age could be accomplished with std::time::Duration (I read the source code) and, IMO, std::time::Duration is better because it receives first-party support from the rust developers, I think it would be reasonable.

If you liked, I could open a pr with this.

@SergioBenitez
Copy link
Member

std::time is not actively maintained or improved, so it does not particularly receive first-part support from the Rust team. All maintenance and improvements were punted to the time crate, which itself became stale but was eventually taken over and is now maintained. Furthermore, std::time does not contain the functionality we need, in particular, parsing and manipulation of times and duration, so we simply cannot use it as-is in cookie.

You might consider taking advantage of the several TryFrom implementations in time for std::time types. For instance, something like the following might work:

cookie.set_max_age(Some(std_duration.try_into().expect("infallible")));

Alternatively, just add time to your Cargo.toml or ask axum to properly re-export time.

@SergioBenitez SergioBenitez closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2023
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

2 participants