Skip to content

Commit 1a33d7a

Browse files
committed
auto merge of #16626 : ruud-v-a/rust/duration-reform, r=brson
This changes the internal representation of `Duration` from days: i32, secs: i32, nanos: u32 to secs: i64, nanos: i32 This resolves #16466. Note that `nanos` is an `i32` and not `u32` as suggested, because `i32` is easier to deal with, and it is not exposed anyway. Some methods now take `i64` instead of `i32` due to the increased range. Some methods, like `num_milliseconds`, now return an `Option<i64>` instead of `i64`, because the range of `Duration` is now larger than e.g. 2^63 milliseconds. A few remarks: - Negating `MIN` is impossible. I chose to return `MAX` as `-MIN`, but it is one nanosecond less than the actual negation. Is this the desired behaviour? - In `std::io::timer`, some functions accept a `Duration`, which is internally converted into a number of milliseconds. However, the range of `Duration` is now larger than 2^64 milliseconds. There is already a FIXME in the file that this should be addressed (without a ticket number though). I chose to silently use 0 ms if the duration is too long. Is that right, as long as the backend still uses milliseconds? - Negative durations are not formatted correctly, but they were not formatted correctly before either.
2 parents ba39b50 + 447b64e commit 1a33d7a

File tree

3 files changed

+200
-279
lines changed

3 files changed

+200
-279
lines changed

src/libstd/io/net/tcp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ impl TcpStream {
9797
/// the specified duration.
9898
///
9999
/// This is the same as the `connect` method, except that if the timeout
100-
/// specified (in milliseconds) elapses before a connection is made an error
101-
/// will be returned. The error's kind will be `TimedOut`.
100+
/// specified elapses before a connection is made an error will be
101+
/// returned. The error's kind will be `TimedOut`.
102102
///
103103
/// Note that the `addr` argument may one day be split into a separate host
104104
/// and port, similar to the API seen in `connect`.

src/libstd/io/net/unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl UnixStream {
6161
/// Connect to a pipe named by `path`, timing out if the specified number of
6262
/// milliseconds.
6363
///
64-
/// This function is similar to `connect`, except that if `timeout_ms`
64+
/// This function is similar to `connect`, except that if `timeout`
6565
/// elapses the function will return an error of kind `TimedOut`.
6666
///
6767
/// If a `timeout` with zero or negative duration is specified then

0 commit comments

Comments
 (0)