use crate::ConstInit;
#[doc = crate::_tags!(time)]
#[doc = crate::_doc_meta!{location("phys/time")}]
#[must_use]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Timed<V, T> {
pub value: V,
pub time: T,
}
#[doc = crate::_tags!(time maybe)]
#[doc = crate::_doc_meta!{location("phys/time")}]
pub type MaybeTimed<V, T> = Timed<V, Option<T>>;
#[rustfmt::skip]
impl<V, T> Timed<V, T> {
#[inline(always)]
pub const fn new(value: V, time: T) -> Self { Self { value, time } }
#[inline(always)]
pub const fn copy_parts(self) -> (V, T) where V: Copy, T: Copy { (self.value, self.time) }
#[inline(always)]
pub fn into_parts(self) -> (V, T) { (self.value, self.time) }
#[inline(always)]
pub const fn as_ref(&self) -> Timed<&V, &T> {
Timed { value: &self.value, time: &self.time }
}
#[inline(always)]
pub const fn as_mut(&mut self) -> Timed<&mut V, &mut T> {
Timed { value: &mut self.value, time: &mut self.time }
}
#[inline(always)]
pub fn map_value<V2, F>(self, f: F) -> Timed<V2, T>
where
F: FnOnce(V) -> V2,
{
Timed { value: f(self.value), time: self.time }
}
#[inline(always)]
pub fn map_time<T2, F>(self, f: F) -> Timed<V, T2>
where
F: FnOnce(T) -> T2,
{
Timed { value: self.value, time: f(self.time) }
}
#[inline(always)]
pub fn map<V2, T2, FV, FT>(self, fv: FV, ft: FT) -> Timed<V2, T2>
where
FV: FnOnce(V) -> V2,
FT: FnOnce(T) -> T2,
{
Timed { value: fv(self.value), time: ft(self.time) }
}
}
impl<V: ConstInit, T: ConstInit> ConstInit for Timed<V, T> {
const INIT: Self = Self { value: V::INIT, time: T::INIT };
}