Skip to content

Commit 6caa350

Browse files
authored
Rollup merge of #81465 - joshtriplett:duration-formatting-documentation, r=m-ou-se
Add documentation about formatting `Duration` values Explain why Duration has a Debug impl but not a Display impl, and mention the use of Unicode.
2 parents acca818 + 8fd2f0c commit 6caa350

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/core/src/time.rs

+11
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ const MICROS_PER_SEC: u64 = 1_000_000;
4848
///
4949
/// let ten_millis = Duration::from_millis(10);
5050
/// ```
51+
///
52+
/// # Formatting `Duration` values
53+
///
54+
/// `Duration` intentionally does not have a `Display` impl, as there are a
55+
/// variety of ways to format spans of time for human readability. `Duration`
56+
/// provides a `Debug` impl that shows the full precision of the value.
57+
///
58+
/// The `Debug` output uses the non-ASCII "µs" suffix for microseconds. If your
59+
/// program output may appear in contexts that cannot rely on full Unicode
60+
/// compatibility, you may wish to format `Duration` objects yourself or use a
61+
/// crate to do so.
5162
#[stable(feature = "duration", since = "1.3.0")]
5263
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
5364
pub struct Duration {

0 commit comments

Comments
 (0)