From 57e660cbb62c4f4aa1272f8b2618cd968ff45701 Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sat, 30 Nov 2024 16:05:01 +0100 Subject: [PATCH] time: add a tick() function to Periodically to avoid needing Fn --- src/time.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/time.rs b/src/time.rs index a59a2c7..6e0d522 100644 --- a/src/time.rs +++ b/src/time.rs @@ -23,9 +23,17 @@ impl Periodically { } pub fn run(&mut self, f: F) where F: FnOnce() { - if self.last_run.elapsed() >= self.duration { + if self.tick() { f(); + } + } + + pub fn tick(&mut self) -> bool { + if self.last_run.elapsed() >= self.duration { self.last_run = Instant::now(); + true + } else { + false } } }