Instant is more suitable than SystemTime for spinners
This commit is contained in:
parent
f88c077f99
commit
1bcb624ae6
@ -1,4 +1,4 @@
|
||||
use std::{collections::HashMap, time::SystemTime};
|
||||
use std::{collections::HashMap, time::Instant};
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct ProgressSpinners {
|
||||
@ -25,7 +25,7 @@ fn default() -> Self {
|
||||
pub struct Spinner {
|
||||
frames: Vec<&'static str>,
|
||||
count: usize,
|
||||
start: Option<SystemTime>,
|
||||
start: Option<Instant>,
|
||||
interval: u64,
|
||||
}
|
||||
|
||||
@ -50,14 +50,13 @@ pub fn dots(interval: u64) -> Self {
|
||||
}
|
||||
|
||||
pub fn start(&mut self) {
|
||||
self.start = Some(SystemTime::now());
|
||||
self.start = Some(Instant::now());
|
||||
}
|
||||
|
||||
pub fn frame(&self) -> Option<&str> {
|
||||
let idx = (self
|
||||
.start
|
||||
.map(|time| SystemTime::now().duration_since(time))?
|
||||
.ok()?
|
||||
.map(|time| Instant::now().duration_since(time))?
|
||||
.as_millis()
|
||||
/ self.interval as u128) as usize
|
||||
% self.count;
|
||||
|
Loading…
Reference in New Issue
Block a user