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

libtime: Implement Add and Sub for Timespec. #16573

Merged
merged 1 commit into from
Aug 19, 2014

Conversation

ruuda
Copy link
Contributor

@ruuda ruuda commented Aug 18, 2014

This implements Add and Sub for Timespec, which enables Timespec to be used as a time span. For example:

let begin = get_time();
// Do some stuff.
let end = get_time();
let delta = end - begin;
println!("Doing stuff took {}.{:09d} seconds.", delta.sec, delta.nsec);

This resolves one of the points mentioned in #2153.

bors added a commit that referenced this pull request Aug 19, 2014
This implements `Add` and `Sub` for `Timespec`, which enables `Timespec` to be used as a time span. For example:

```rust
let begin = get_time();
// Do some stuff.
let end = get_time();
let delta = end - begin;
println!("Doing stuff took {}.{:09d} seconds.", delta.sec, delta.nsec);
```
This resolves one of the points mentioned in #2153.
@sfackler
Copy link
Member

Isn't this exactly the use case for the Duration type?

@bors bors closed this Aug 19, 2014
@bors bors merged commit 62b1fbe into rust-lang:master Aug 19, 2014
@ruuda
Copy link
Contributor Author

ruuda commented Aug 19, 2014

I had not noticed Duration. (Edit: probably because it is in std::time instead of time.) You are right, it would be better to implement Sub<Timespec, Duration> and Add<Duration, Timespec> instead. I could do that and fix #16466 in the process? It would not allow subtracting a Duration from Timespec without multidispatch though, unless we introduce an extra trait.

bors added a commit that referenced this pull request Aug 31, 2014
This changes the `Add` and `Sub` implementations for `Timespec` introduced in #16573 to use `Duration` as the time span type instead of `Timespec` itself, as [suggested](#16573 (comment)) by @sfackler.

This depends on #16626, because is uses `Duration::seconds(i64)`, whereas currently `Duration::seconds` takes an `i32`.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 18, 2024
internal: Remove salsa doc compile tests

These don't play well with the github CI error annotations
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.

4 participants