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

Posted 2 months ago

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

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.

Created 2 months ago

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:


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