]> git.lizzy.rs Git - rust.git/commitdiff
std: Improve Duration comments
authorBrian Anderson <banderson@mozilla.com>
Thu, 7 Aug 2014 22:45:48 +0000 (15:45 -0700)
committerBrian Anderson <banderson@mozilla.com>
Wed, 13 Aug 2014 18:31:48 +0000 (11:31 -0700)
src/libstd/time/duration.rs

index 7f31df96b0740eb4efd011c8713d2d7158f3c03a..ddec5f8b3b8b5e175ac558eaad8b022bb2c522b3 100644 (file)
@@ -39,8 +39,8 @@ macro_rules! try_opt(
 #[deriving(PartialEq, Eq, PartialOrd, Ord)]
 pub struct Duration {
     days: i32,
-    secs: u32,
-    nanos: u32,
+    secs: u32,  // Always < SECS_PER_DAY
+    nanos: u32, // Always < NANOS_PR_SECOND
 }
 
 /// The minimum possible `Duration`.
@@ -81,18 +81,13 @@ pub fn weeks(weeks: i32) -> Duration {
 
     /// Makes a new `Duration` with given number of days.
     /// Equivalent to `Duration::new(days, 0, 0)`.
-    ///
-    /// Fails when the duration is out of bounds.
     #[inline]
     pub fn days(days: i32) -> Duration {
-        let days = days.to_i32().expect("Duration::days out of bounds");
         Duration { days: days, secs: 0, nanos: 0 }
     }
 
     /// Makes a new `Duration` with given number of hours.
     /// Equivalent to `Duration::new(0, hours * 3600, 0)` with overflow checks.
-    ///
-    /// Fails when the duration is out of bounds.
     #[inline]
     pub fn hours(hours: i32) -> Duration {
         let (days, hours) = div_mod_floor(hours, (SECS_PER_DAY / 3600));
@@ -102,8 +97,6 @@ pub fn hours(hours: i32) -> Duration {
 
     /// Makes a new `Duration` with given number of minutes.
     /// Equivalent to `Duration::new(0, mins * 60, 0)` with overflow checks.
-    ///
-    /// Fails when the duration is out of bounds.
     #[inline]
     pub fn minutes(mins: i32) -> Duration {
         let (days, mins) = div_mod_floor(mins, (SECS_PER_DAY / 60));
@@ -113,8 +106,6 @@ pub fn minutes(mins: i32) -> Duration {
 
     /// Makes a new `Duration` with given number of seconds.
     /// Equivalent to `Duration::new(0, secs, 0)`.
-    ///
-    /// Fails when the duration is out of bounds.
     #[inline]
     pub fn seconds(secs: i32) -> Duration {
         let (days, secs) = div_mod_floor(secs, SECS_PER_DAY);
@@ -123,8 +114,6 @@ pub fn seconds(secs: i32) -> Duration {
 
     /// Makes a new `Duration` with given number of milliseconds.
     /// Equivalent to `Duration::new(0, 0, millis * 1_000_000)` with overflow checks.
-    ///
-    /// Fails when the duration is out of bounds.
     #[inline]
     pub fn milliseconds(millis: i32) -> Duration {
         let (secs, millis) = div_mod_floor(millis, (NANOS_PER_SEC / 1_000_000));
@@ -134,8 +123,6 @@ pub fn milliseconds(millis: i32) -> Duration {
 
     /// Makes a new `Duration` with given number of microseconds.
     /// Equivalent to `Duration::new(0, 0, micros * 1_000)` with overflow checks.
-    ///
-    /// Fails when the duration is out of bounds.
     #[inline]
     pub fn microseconds(micros: i32) -> Duration {
         let (secs, micros) = div_mod_floor(micros, (NANOS_PER_SEC / 1_000));
@@ -145,8 +132,6 @@ pub fn microseconds(micros: i32) -> Duration {
 
     /// Makes a new `Duration` with given number of nanoseconds.
     /// Equivalent to `Duration::new(0, 0, nanos)`.
-    ///
-    /// Fails when the duration is out of bounds.
     #[inline]
     pub fn nanoseconds(nanos: i32) -> Duration {
         let (secs, nanos) = div_mod_floor(nanos, NANOS_PER_SEC);