#[cfg(test)]
mod tests;
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum WaitTimeoutResult<T> {
Reached,
TimedOut(T),
}
impl<T> WaitTimeoutResult<T> {
#[must_use]
#[inline]
pub const fn is_reached(&self) -> bool {
matches!(self, WaitTimeoutResult::Reached)
}
#[must_use]
#[inline]
pub const fn is_timed_out(&self) -> bool {
matches!(self, WaitTimeoutResult::TimedOut(_))
}
#[must_use]
#[inline]
pub fn timed_out(self) -> Option<T> {
match self {
WaitTimeoutResult::Reached => None,
WaitTimeoutResult::TimedOut(t) => Some(t),
}
}
#[inline]
pub fn ok<V>(self, v: V) -> Result<V, T> {
match self {
WaitTimeoutResult::Reached => Ok(v),
WaitTimeoutResult::TimedOut(e) => Err(e),
}
}
#[inline]
pub fn ok_by<V, F: FnOnce() -> V>(self, v: F) -> Result<V, T> {
match self {
WaitTimeoutResult::Reached => Ok(v()),
WaitTimeoutResult::TimedOut(e) => Err(e),
}
}
}