pub enum WaitTimeoutResult<R> {
Ready(R),
TimedOut,
}Expand description
Result of waiting for a predicate with an overall timeout.
This type is returned by
Monitor::wait_timeout_while and
Monitor::wait_timeout_until. It is
more explicit than Option<R>: a ready predicate produces Self::Ready,
while an expired timeout produces Self::TimedOut.
§Type Parameters
R- The value produced after the protected state satisfies the predicate.
§Example
use std::time::Duration;
use qubit_lock::{Monitor, WaitTimeoutResult};
let monitor = Monitor::new(true);
let result = monitor.wait_timeout_until(
Duration::from_secs(1),
|ready| *ready,
|ready| {
*ready = false;
"ready"
},
);
assert_eq!(result, WaitTimeoutResult::Ready("ready"));Variants§
Ready(R)
The predicate became ready before the timeout and produced this value.
TimedOut
The timeout elapsed before the predicate became ready.
Implementations§
Source§impl<R> WaitTimeoutResult<R>
impl<R> WaitTimeoutResult<R>
Sourcepub const fn is_ready(&self) -> bool
pub const fn is_ready(&self) -> bool
Returns true when the result contains a ready value.
§Returns
true for Self::Ready, otherwise false.
Sourcepub const fn is_timed_out(&self) -> bool
pub const fn is_timed_out(&self) -> bool
Returns true when the timeout elapsed before the predicate was ready.
§Returns
true for Self::TimedOut, otherwise false.
Sourcepub fn into_option(self) -> Option<R>
pub fn into_option(self) -> Option<R>
Converts this result into an Option.
§Returns
Some(value) for Self::Ready, or None for Self::TimedOut.
Sourcepub fn map<U, F: FnOnce(R) -> U>(self, f: F) -> WaitTimeoutResult<U>
pub fn map<U, F: FnOnce(R) -> U>(self, f: F) -> WaitTimeoutResult<U>
Maps a ready value while preserving timeout status.
§Arguments
f- Closure applied to the contained value when this result isSelf::Ready.
§Returns
Self::Ready containing the mapped value, or
WaitTimeoutResult::TimedOut when this result timed out.
Trait Implementations§
Source§impl<R: Clone> Clone for WaitTimeoutResult<R>
impl<R: Clone> Clone for WaitTimeoutResult<R>
Source§fn clone(&self) -> WaitTimeoutResult<R>
fn clone(&self) -> WaitTimeoutResult<R>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<R: Debug> Debug for WaitTimeoutResult<R>
impl<R: Debug> Debug for WaitTimeoutResult<R>
Source§impl<R: PartialEq> PartialEq for WaitTimeoutResult<R>
impl<R: PartialEq> PartialEq for WaitTimeoutResult<R>
Source§fn eq(&self, other: &WaitTimeoutResult<R>) -> bool
fn eq(&self, other: &WaitTimeoutResult<R>) -> bool
self and other values to be equal, and is used by ==.