Instant is more suitable than SystemTime for spinners

pull/1651/head
Blaž Hrastnik 3 years ago
parent f88c077f99
commit 1bcb624ae6

@ -1,4 +1,4 @@
use std::{collections::HashMap, time::SystemTime}; use std::{collections::HashMap, time::Instant};
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct ProgressSpinners { pub struct ProgressSpinners {
@ -25,7 +25,7 @@ impl Default for Spinner {
pub struct Spinner { pub struct Spinner {
frames: Vec<&'static str>, frames: Vec<&'static str>,
count: usize, count: usize,
start: Option<SystemTime>, start: Option<Instant>,
interval: u64, interval: u64,
} }
@ -50,14 +50,13 @@ impl Spinner {
} }
pub fn start(&mut self) { pub fn start(&mut self) {
self.start = Some(SystemTime::now()); self.start = Some(Instant::now());
} }
pub fn frame(&self) -> Option<&str> { pub fn frame(&self) -> Option<&str> {
let idx = (self let idx = (self
.start .start
.map(|time| SystemTime::now().duration_since(time))? .map(|time| Instant::now().duration_since(time))?
.ok()?
.as_millis() .as_millis()
/ self.interval as u128) as usize / self.interval as u128) as usize
% self.count; % self.count;

Loading…
Cancel
Save