Skip to content

Commit

Permalink
Document show_duration_as_seconds()
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Dec 9, 2024
1 parent 821df55 commit 228b18d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/show_duration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
use std::fmt::{self, Write};
use std::time::Duration;

/// Returns a structure that displays the given [`Duration`] as a
/// floating-point number of seconds using no more precision than is necessary.
///
/// # Example
///
/// ```
/// # use rswodlib::show_duration::show_duration_as_seconds;
/// # use std::time::Duration;
/// let d1 = Duration::from_secs(42);
/// assert_eq!(show_duration_as_seconds(d1).to_string(), "42");
///
/// let d2 = Duration::from_nanos(123_000_000);
/// assert_eq!(show_duration_as_seconds(d2).to_string(), "0.123");
/// ```
pub fn show_duration_as_seconds(d: Duration) -> ShowDurationAsSeconds {
ShowDurationAsSeconds(d)
}
Expand Down

0 comments on commit 228b18d

Please sign in to comment.