Suggest less bug-prone construction of Duration in docs

This commit is contained in:
Ben Wiederhake 2023-12-23 07:30:47 +01:00
parent e64f8495e7
commit 27ba1c1a8c

View File

@ -268,6 +268,11 @@ pub const fn from_micros(micros: u64) -> Duration {
/// Creates a new `Duration` from the specified number of nanoseconds. /// 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 /// # Examples
/// ///
/// ``` /// ```