From 78db4168a53b3e120c883a1c8ee1625c97e4fc42 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 31 Jul 2024 14:21:35 -0700 Subject: [PATCH] constructors --- src/timer.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/timer.rs b/src/timer.rs index 84b7d8a..fb28b51 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -5,12 +5,19 @@ pub struct Unpaused; pub trait PauseState{ const IS_PAUSED:bool; + fn new()->Self; } impl PauseState for Paused{ const IS_PAUSED:bool=true; + fn new()->Self{ + Self + } } impl PauseState for Unpaused{ const IS_PAUSED:bool=false; + fn new()->Self{ + Self + } } pub struct Realtime{ @@ -106,6 +113,30 @@ impl std::fmt::Display for Error{ } impl std::error::Error for Error{} +impl TimerFixed{ + pub fn new(time:Time,new_time:Time)->Self{ + let mut timer=Self{ + state:Realtime::identity(), + _paused:P::new(), + }; + timer.set_time(time,new_time); + timer + } +} +impl TimerFixed{ + pub fn new(time:Time,new_time:Time,scale:Ratio64)->Self{ + let mut timer=Self{ + state:Scaled::with_scale(scale), + _paused:P::new(), + }; + timer.set_time(time,new_time); + timer + } + pub fn unit(time:Time,new_time:Time)->Self{ + Self::new(time,new_time,Ratio64::ONE) + } +} + impl TimerFixed{ pub fn time(&self,time:Time)->Time{ match P::IS_PAUSED{