1
- // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012-2017 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -18,9 +18,10 @@ const MILLIS_PER_SEC: u64 = 1_000;
18
18
/// A `Duration` type to represent a span of time, typically used for system
19
19
/// timeouts.
20
20
///
21
- /// Each `Duration` is composed of a number of seconds and nanosecond precision.
22
- /// APIs binding a system timeout will typically round up the nanosecond
23
- /// precision if the underlying system does not support that level of precision.
21
+ /// Each `Duration` is composed of a whole number of seconds and a fractional part
22
+ /// represented in nanoseconds. If the underlying system does not support
23
+ /// nanosecond-level precision, APIs binding a system timeout will typically round up
24
+ /// the number of nanoseconds.
24
25
///
25
26
/// `Duration`s implement many common traits, including [`Add`], [`Sub`], and other
26
27
/// [`ops`] traits.
@@ -50,11 +51,11 @@ pub struct Duration {
50
51
}
51
52
52
53
impl Duration {
53
- /// Creates a new `Duration` from the specified number of seconds and
54
- /// additional nanosecond precision .
54
+ /// Creates a new `Duration` from the specified number of whole seconds and
55
+ /// additional nanoseconds .
55
56
///
56
- /// If the nanoseconds is greater than 1 billion (the number of nanoseconds
57
- /// in a second), then it will carry over into the seconds provided.
57
+ /// If the number of nanoseconds is greater than 1 billion (the number of
58
+ /// nanoseconds in a second), then it will carry over into the seconds provided.
58
59
///
59
60
/// # Panics
60
61
///
@@ -77,7 +78,7 @@ impl Duration {
77
78
Duration { secs : secs, nanos : nanos }
78
79
}
79
80
80
- /// Creates a new `Duration` from the specified number of seconds.
81
+ /// Creates a new `Duration` from the specified number of whole seconds.
81
82
///
82
83
/// # Examples
83
84
///
@@ -115,10 +116,10 @@ impl Duration {
115
116
Duration { secs : secs, nanos : nanos }
116
117
}
117
118
118
- /// Returns the number of whole seconds represented by this `Duration`.
119
+ /// Returns the number of _whole_ seconds contained by this `Duration`.
119
120
///
120
- /// The extra precision represented by this duration is ignored (i.e. extra
121
- /// nanoseconds are not represented in the returned value) .
121
+ /// The returned value does not include the fractional (nanosecond) part of the
122
+ /// duration, which can be obtained using [`subsec_nanos`] .
122
123
///
123
124
/// # Examples
124
125
///
@@ -147,7 +148,7 @@ impl Duration {
147
148
#[ inline]
148
149
pub fn as_secs ( & self ) -> u64 { self . secs }
149
150
150
- /// Returns the nanosecond precision represented by this `Duration`.
151
+ /// Returns the fractional part of this `Duration`, in nanoseconds .
151
152
///
152
153
/// This method does **not** return the length of the duration when
153
154
/// represented by nanoseconds. The returned number always represents a
@@ -159,7 +160,8 @@ impl Duration {
159
160
/// use std::time::Duration;
160
161
///
161
162
/// let duration = Duration::from_millis(5010);
162
- /// assert_eq!(duration.subsec_nanos(), 10000000);
163
+ /// assert_eq!(duration.as_secs(), 5);
164
+ /// assert_eq!(duration.subsec_nanos(), 10_000_000);
163
165
/// ```
164
166
#[ stable( feature = "duration" , since = "1.3.0" ) ]
165
167
#[ inline]
0 commit comments