use crate::{RunPhase, RunStep, RuntimeTick};
#[doc = crate::_tags!(runtime time)]
#[doc = crate::_doc_location!("run/time")]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct RunFrame<'a, E = (), C = ()> {
step: RunStep<'a, E>,
context: C,
}
impl<'a, E, C> RunFrame<'a, E, C> {
pub const fn new(step: RunStep<'a, E>, context: C) -> Self {
Self { step, context }
}
pub const fn from_parts(
tick: RuntimeTick,
phase: RunPhase,
events: &'a [E],
context: C,
) -> Self {
Self { step: RunStep::new(tick, phase, events), context }
}
#[must_use]
pub fn step(&self) -> &RunStep<'a, E> {
&self.step
}
pub const fn tick(&self) -> RuntimeTick {
self.step.tick()
}
pub const fn phase(&self) -> RunPhase {
self.step.phase()
}
pub const fn events(&self) -> &'a [E] {
self.step.events()
}
pub const fn is_running(&self) -> bool {
self.step.is_running()
}
#[must_use]
pub fn context(&self) -> &C {
&self.context
}
#[must_use]
pub fn context_mut(&mut self) -> &mut C {
&mut self.context
}
#[must_use]
pub fn into_parts(self) -> (RunStep<'a, E>, C) {
(self.step, self.context)
}
#[must_use]
pub fn map_context<T, F: FnOnce(C) -> T>(self, f: F) -> RunFrame<'a, E, T> {
let (step, context) = self.into_parts();
RunFrame { step, context: f(context) }
}
}