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

Add checked_mul and checked_div #1565

Merged
merged 1 commit into from
Apr 8, 2024
Merged

Conversation

Zomtir
Copy link
Contributor

@Zomtir Zomtir commented Apr 8, 2024

Adds checked variants of TimeDelta::mul and TimeDelta::div as proposed in #1469.

If you spot other unhandled cases let me know.

Regarding checked_div, I think it is impossible to overflow because you cannot divide by integers between -1 and +1 other than 0.

cc @pitdicker

Copy link

codecov bot commented Apr 8, 2024

Codecov Report

Attention: Patch coverage is 96.77419% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 91.81%. Comparing base (f8cecbe) to head (80c1bb0).

Files Patch % Lines
src/time_delta.rs 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1565      +/-   ##
==========================================
+ Coverage   91.80%   91.81%   +0.01%     
==========================================
  Files          37       37              
  Lines       18151    18164      +13     
==========================================
+ Hits        16664    16678      +14     
+ Misses       1487     1486       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@pitdicker pitdicker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you spot other unhandled cases let me know.

Not that easy to spot 😆.

src/time_delta.rs Show resolved Hide resolved
src/time_delta.rs Show resolved Hide resolved
src/time_delta.rs Outdated Show resolved Hide resolved
src/time_delta.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@pitdicker pitdicker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Zomtir
Copy link
Contributor Author

Zomtir commented Apr 8, 2024

Half-open range patterns became stable in Rust 1.59.0, the CI is on an older version so i had to use full ranges

    // half-open
    ..=-1 => (secs - 1, nanos + NANOS_PER_SEC),
    NANOS_PER_SEC.. => (secs + 1, nanos - NANOS_PER_SEC),
    
    // full range
    i32::MIN..=-1 => (secs - 1, nanos + NANOS_PER_SEC),
    NANOS_PER_SEC..=i32::MAX => (secs + 1, nanos - NANOS_PER_SEC),

@pitdicker
Copy link
Collaborator

Half-open range patterns became stable in Rust 1.59.0, the CI is on an older version so i had to use full ranges

The CI is checking our MSRV of 1.61.

@Zomtir
Copy link
Contributor Author

Zomtir commented Apr 8, 2024

Half-open range patterns became stable in Rust 1.59.0, the CI is on an older version so i had to use full ranges

The CI is checking our MSRV of 1.61.

Woops! Half-open ranges work on my system (TM) : Rust 1.74. So it got stable somewhere in between.

@pitdicker
Copy link
Collaborator

Rust 1.66 stabilized the feature: https://blog.rust-lang.org/2022/12/15/Rust-1.66.0.html#other-changes

@pitdicker pitdicker merged commit ffc75e5 into chronotope:main Apr 8, 2024
35 checks passed
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.

3 participants