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 TryFrom for TimeSpec/Duration conversions which may underflow/overflow #2522

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sirhcel
Copy link

@sirhcel sirhcel commented Oct 20, 2024

What does this PR do

  • This is a follow-up to Shouldn't TimeSpec::from_duration preserve monotonicity? #2479 for switching from From to TryFrom for conversions between TimeSpec and Duration which may underflow or overflow
  • I learned that From and TryFrom can not co-exist and so adding the latter and deprecating the former does not seem feasible and it looks like we are left with a breaking change here
  • I'm starting this as a draft PR for
    • Discussing the desired level of detail for reporting errors from TryFrom. The underlying integer conversions return a TryFromIntError which informs that the conversion has failed but gives no specific reason.
    • Getting feedback from CI
    • Adding tests for the conversions once the course for this PR is set
    • Adding a change log once the course for this PR is set

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

Their underlying types are not congruent and therefor "lossy"
conversions with usually unexpected behavior result from it.

Let's make this explicit by switching from From conversions to TryFrom.
The error types used there are quite spartan. Is there a need for more
detailed reporting?
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

Successfully merging this pull request may close these issues.

1 participant