Suggest less bug-prone construction of Duration in docs
This commit is contained in:
parent
e64f8495e7
commit
27ba1c1a8c
@ -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
|
||||
///
|
||||
/// ```
|
||||
|
Loading…
Reference in New Issue
Block a user