A very simple Stopwatch for the command line
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
498 B

5 years ago
  1. use std::convert::From;
  2. use std::{fmt, time};
  3. #[derive(Debug, Clone)]
  4. pub struct FmtDuration(time::Duration);
  5. impl fmt::Display for FmtDuration {
  6. fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
  7. let secs = self.0.as_secs();
  8. let millis = self.0.subsec_millis();
  9. write!(f, "{:02}:{:02}:{:03}", secs / 60, secs % 60, millis)
  10. }
  11. }
  12. impl From<time::Duration> for FmtDuration {
  13. fn from(dur: time::Duration) -> Self {
  14. FmtDuration(dur)
  15. }
  16. }