constructors

This commit is contained in:
Quaternions 2024-07-31 14:21:35 -07:00
parent ce0572485b
commit 78db4168a5

View File

@ -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<P:PauseState> TimerFixed<Realtime,P>{
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<P:PauseState> TimerFixed<Scaled,P>{
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<T:TimerState,P:PauseState> TimerFixed<T,P>{
pub fn time(&self,time:Time)->Time{
match P::IS_PAUSED{