qubit_lock/monitor/wait_timeout_result.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! # Wait Timeout Result
11//!
12//! Provides the result returned by predicate-based timed monitor waits.
13//!
14
15/// Result of waiting for a predicate with an overall timeout.
16///
17/// This type is returned by
18/// [`Monitor::wait_timeout_while`](super::Monitor::wait_timeout_while) and
19/// [`Monitor::wait_timeout_until`](super::Monitor::wait_timeout_until). It is
20/// more explicit than `Option<R>`: a ready predicate produces [`Self::Ready`],
21/// while an expired timeout produces [`Self::TimedOut`].
22///
23/// # Type Parameters
24///
25/// * `R` - The value produced after the protected state satisfies the
26/// predicate.
27///
28/// # Example
29///
30/// ```rust
31/// use std::time::Duration;
32///
33/// use qubit_lock::lock::{Monitor, WaitTimeoutResult};
34///
35/// let monitor = Monitor::new(true);
36/// let result = monitor.wait_timeout_until(
37/// Duration::from_secs(1),
38/// |ready| *ready,
39/// |ready| {
40/// *ready = false;
41/// "ready"
42/// },
43/// );
44///
45/// assert_eq!(result, WaitTimeoutResult::Ready("ready"));
46/// ```
47#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub enum WaitTimeoutResult<R> {
49 /// The predicate became ready before the timeout and produced this value.
50 Ready(R),
51 /// The timeout elapsed before the predicate became ready.
52 TimedOut,
53}