Skip to content

Commit 27ba1c1

Browse files
committed
Suggest less bug-prone construction of Duration in docs
1 parent e64f849 commit 27ba1c1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/core/src/time.rs

+5
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ impl Duration {
268268

269269
/// Creates a new `Duration` from the specified number of nanoseconds.
270270
///
271+
/// Note: Using this on the return value of `as_nanos()` might cause unexpected behavior:
272+
/// `as_nanos()` returns a u128, and can return values that do not fit in u64, e.g. 585 years.
273+
/// Instead, consider using the pattern `Duration::new(d.as_secs(), d.subsec_nanos())`
274+
/// if you cannot copy/clone the Duration directly.
275+
///
271276
/// # Examples
272277
///
273278
/// ```

0 commit comments

Comments
 (0)