@@ -308,31 +308,32 @@ impl Duration {
308
308
Duration { secs, nanos : subsec_nanos }
309
309
}
310
310
311
- /// Creates a new Duration from the specified number of nanoseconds.
311
+ /// Creates a new ` Duration` from the specified number of nanoseconds.
312
312
///
313
313
/// # Panics
314
314
///
315
- /// Panics if the given number of nanoseconds is greater than what Duration can handle,
316
- /// which is `(u64::MAX * NANOS_PER_SEC) + NANOS_PER_SEC - 1`
317
- /// Use this function if you need to specify time greater than what can fit in u64
318
- /// (around 584 years).
315
+ /// Panics if the given number of nanoseconds is greater than [`Duration::MAX`].
319
316
///
320
317
/// # Examples
321
318
///
322
319
/// ```
323
320
/// #![feature(duration_from_nanos_u128)]
324
321
/// use std::time::Duration;
325
- /// let time_in_nanos = 2u128.pow(64);
326
- /// let duration = Duration::from_nanos_u128(time_in_nanos);
322
+ ///
323
+ /// let duration = Duration::from_nanos_u128(1_000_000_321);
324
+ ///
325
+ /// assert_eq!(1, duration.as_secs());
326
+ /// assert_eq!(321, duration.subsec_nanos());
327
327
/// ```
328
328
#[ unstable( feature = "duration_from_nanos_u128" , issue = "139201" ) ]
329
329
#[ must_use]
330
330
#[ inline]
331
+ #[ track_caller]
331
332
pub const fn from_nanos_u128 ( nanos : u128 ) -> Duration {
332
333
const NANOS_PER_SEC : u128 = self :: NANOS_PER_SEC as u128 ;
333
334
let secs: u128 = nanos / NANOS_PER_SEC ;
334
335
if secs > u64:: MAX as u128 {
335
- panic ! ( "overflow in duration in Duration::from_nanos_u128" ) ;
336
+ panic ! ( "overflow in ` Duration::from_nanos_u128` " ) ;
336
337
}
337
338
let subsec_nanos = ( nanos % NANOS_PER_SEC ) as u32 ;
338
339
// SAFETY: x % 1_000_000_000 < 1_000_000_000 also, subsec_nanos >= 0 since u128 >=0 and u32 >=0
0 commit comments