-
Notifications
You must be signed in to change notification settings - Fork 667
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
Shouldn't TimeSpec::from_duration preserve monotonicity? #2479
Comments
The problem is that a Unix |
This is a fair point against saturating.
What about transitioning towards this impl over some time? I could prepare PRs for adding |
Yes, that would be good. |
When creating a
TimeSpec
from astd::time::Duration
with more thanlibc::time_t
seconds, the resulting value might be negative and will no longer preserve monotonicity with respect to the input duration. This happens to the integer casting inTimeSpec::from_duration
.See this example on Rust Playground.
I learned about this behavior through errors for negative timeouts from
ppoll
on Linux at runtime (serialport/serialport-rs#207). I did not expect this for the "porcellain" typeDuration
and the docs did not hint at it. And likely other users of the "porcellain" as well. When manually converting to the "plumbing" typetime_t
I wold have looked deeper into the nitty gritty integer casts and cared for this case by saturating.So shouldn't
TimeSpec::from_duration
preserve monotonicity? Isn't an inaccurate but still largeTimeSpec
less surprising?The text was updated successfully, but these errors were encountered: