pub enum TimeBudgetError<R> {
Clock {
resource: R,
source: TimeError,
},
Expired {
resource: R,
deadline: MonotonicInstant,
now: MonotonicInstant,
},
WouldExpire {
resource: R,
deadline: MonotonicInstant,
now: MonotonicInstant,
requested: Duration,
},
}time only.Expand description
Failure facts for a continuous deadline check.
§Type Parameters
R- Caller-defined resource value retained for diagnostics.
§Examples
use std::time::Duration;
use qubit_budget::TimeBudget;
use qubit_budget::TimeBudgetError;
use qubit_clock::ManualMonotonicClock;
let clock = ManualMonotonicClock::new_shared();
let budget = TimeBudget::for_duration("request", clock.clone(), Duration::from_secs(1))
.expect("the deadline should be representable");
clock.advance(Duration::from_secs(1)).expect("the clock should advance");
assert!(matches!(budget.check(), Err(TimeBudgetError::Expired { .. })));Variants§
Clock
The clock rejected a domain or instant operation.
Fields
resource: RResource value associated with the deadline.
Expired
The fixed deadline has already been reached.
Fields
resource: RResource value associated with the deadline.
deadline: MonotonicInstantFixed deadline.
now: MonotonicInstantCurrent sampled instant.
WouldExpire
A prospective operation would reach or pass the deadline.
Fields
resource: RResource value associated with the deadline.
deadline: MonotonicInstantFixed deadline.
now: MonotonicInstantCurrent sampled instant.
Implementations§
Source§impl<R> TimeBudgetError<R>
impl<R> TimeBudgetError<R>
Sourcepub fn into_resource(self) -> R
pub fn into_resource(self) -> R
Sourcepub const fn clock_error(&self) -> Option<&TimeError>
pub const fn clock_error(&self) -> Option<&TimeError>
Returns the underlying clock error, when present.
§Returns
Some contains the underlying clock error for Self::Clock; None
is returned for Self::Expired and Self::WouldExpire.
Sourcepub const fn deadline(&self) -> Option<MonotonicInstant>
pub const fn deadline(&self) -> Option<MonotonicInstant>
Returns the deadline for deadline-related errors.
§Returns
Some contains the fixed deadline for Self::Expired and
Self::WouldExpire; None is returned for Self::Clock.
Sourcepub const fn now(&self) -> Option<MonotonicInstant>
pub const fn now(&self) -> Option<MonotonicInstant>
Returns the sampled instant for deadline-related errors.
§Returns
Some contains the sampled instant for Self::Expired and
Self::WouldExpire; None is returned for Self::Clock.
Sourcepub const fn requested(&self) -> Option<Duration>
pub const fn requested(&self) -> Option<Duration>
Returns the prospective duration for a would-expire error.
§Returns
Some contains the requested duration for Self::WouldExpire;
None is returned for Self::Clock and Self::Expired.
Trait Implementations§
Source§impl<R: Debug> Debug for TimeBudgetError<R>
impl<R: Debug> Debug for TimeBudgetError<R>
Source§impl<R> Display for TimeBudgetError<R>where
R: Debug,
impl<R> Display for TimeBudgetError<R>where
R: Debug,
Source§impl<R> Error for TimeBudgetError<R>
impl<R> Error for TimeBudgetError<R>
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()