Document Duration's Display format (#517)

This commit is contained in:
Brandon W Maister 2021-01-22 12:12:23 -05:00 committed by GitHub
parent 2b53360471
commit 19ec092d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,6 +45,7 @@ macro_rules! try_opt {
}
/// ISO 8601 time duration with nanosecond precision.
///
/// This also allows for the negative duration; see individual methods for details.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct Duration {
@ -373,6 +374,9 @@ impl Div<i32> for Duration {
}
impl fmt::Display for Duration {
/// Format a duration using the [ISO 8601] format
///
/// [ISO 8601]: https://en.wikipedia.org/wiki/ISO_8601#Durations
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// technically speaking, negative duration is not valid ISO 8601,
// but we need to print it anyway.