use crate::{RunCycle, RunPhase, RuntimeTick};
#[doc = crate::_tags!(runtime)]
#[doc = crate::_doc_location!("run/time")]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Runtime<R> {
regime: R,
tick: RuntimeTick,
cycle: RunCycle,
}
impl<R> Runtime<R> {
pub const fn new(regime: R) -> Self {
Self {
regime,
tick: RuntimeTick::new(0),
cycle: RunCycle::new(),
}
}
pub const fn regime(&self) -> &R {
&self.regime
}
pub const fn regime_mut(&mut self) -> &mut R {
&mut self.regime
}
pub const fn tick(&self) -> RuntimeTick {
self.tick
}
pub const fn cycle(&self) -> RunCycle {
self.cycle
}
pub const fn phase(&self) -> RunPhase {
self.cycle.phase()
}
pub const fn can_advance(&self) -> bool {
self.cycle.can_advance()
}
pub const fn tick_once(&mut self) {
self.tick.tick();
}
pub const fn advance_mut(&mut self, delta: u64) {
self.tick.advance_mut(delta);
}
pub const fn transition(&mut self, next: RunPhase) -> bool {
self.cycle.transition(next)
}
}