From 27ba1c1a8ca8654931d9c25f676e98d9f313135e Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sat, 23 Dec 2023 07:30:47 +0100 Subject: [PATCH] Suggest less bug-prone construction of Duration in docs --- library/core/src/time.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/time.rs b/library/core/src/time.rs index b677776443f..850c69d8fc2 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -268,6 +268,11 @@ pub const fn from_micros(micros: u64) -> Duration { /// Creates a new `Duration` from the specified number of nanoseconds. /// + /// Note: Using this on the return value of `as_nanos()` might cause unexpected behavior: + /// `as_nanos()` returns a u128, and can return values that do not fit in u64, e.g. 585 years. + /// Instead, consider using the pattern `Duration::new(d.as_secs(), d.subsec_nanos())` + /// if you cannot copy/clone the Duration directly. + /// /// # Examples /// /// ```