Duration suffix syntax sugar

Similar to what was mentioned in a previous post Pre-RFC: Custom suffixes for integer and float literals I'd like to propose time suffixes for numeric literals, this time only for the Duration type. It would feel very natural and easy to read a duration like 1s, 10ms, 1_000_ns and so on. Duration being on core feels suitable to gain this syntactic sugar similar to other numeric primitives.

With this recent post about IntoFuture and its example about a possible future implementation of IntoFuture for Duration I thought it would be very handy to write something like (1_min + 30_sec + 11_ms).await;


Please no.


We can already have 1.ms() and so on with a trait (I thought there was already a crate for this)


The time crate does this.


Are you talking about std::time::Duration, time::Duration, chrono::Duration (or maybe something else) ? I think a problem with this proposal is that a lot of crates/fns are using non-std Duration objects. The fact that these suffixes would (?) only work with the std ones might be confusing to users.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.