Implement Ord trait for Timespec#4505
Closed
cpeterso wants to merge 6 commits intorust-lang:incomingfrom
cpeterso:impl-timespec-ord
Closed
Implement Ord trait for Timespec#4505cpeterso wants to merge 6 commits intorust-lang:incomingfrom cpeterso:impl-timespec-ord
cpeterso wants to merge 6 commits intorust-lang:incomingfrom
cpeterso:impl-timespec-ord
Conversation
doc: Fold information from the memory model interlude in the tutorial elsewhere
…ed-value s/moved variable/moved value/
RalfJung
added a commit
to RalfJung/rust
that referenced
this pull request
Aug 19, 2025
Use GH app for authenticating pull PRs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note that
Timespecdoes not perform any range checking and this change does not add any!This implementation of
Ordassumes that pre-epochTimespecs have negativesecand positivensecfields. Linux's and Darwin'sstruct timespecfunctions handle pre-epoch timestamps with this "two steps back, half step forward" representation, though I cannot find any documentation that actually puts this in writing. This means that (say) -1.2 seconds is represented byTimespec { sec: -2_i64, nsec: 800_000_000_i32 }, not something likeTimespec { sec: -1_i64, nsec: -200_000_000_i32 }orTimespec { sec: -1_i64, nsec: 200_000_000_i32 }.If we wish to codify this implementation detail, we could make
Timespec nsecunsigned and add range checks assertingnsec <= 999_999_999_u32. btw,struct Tmalso lacks range checking and uses signed integers for fields that can't be negative.