pub enum BudgetError<R, Q = u64>{
LimitExceeded {
resource: R,
observed: Observation<Q>,
maximum: Q,
},
Insufficient {
resource: R,
limit: Q,
remaining: Q,
requested: Q,
},
}Expand description
Aggregate error for APIs that can perform both point and cumulative checks.
APIs with a single failure mode return LimitExceededError or
InsufficientBudgetError directly. This type remains the common carrier
for composite operations and measured-value errors. Releasable pool release
failures use the separate crate::ResourceReleaseError type.
§Type Parameters
R- Caller-defined resource value retained for diagnostics.Q- Copyable measurement value used by the failed constraint.
§Examples
use qubit_budget::BudgetError;
use qubit_budget::LimitExceededError;
let error = BudgetError::from(LimitExceededError::exact("depth", 3_u64, 2));
assert_eq!(error.configured_limit(), 2);
assert_eq!(error.exact_observed(), Some(3));Variants§
LimitExceeded
A point measurement exceeded its configured maximum.
Fields
resource: RResource associated with the failed point check.
observed: Observation<Q>Observed point measurement or safe lower bound.
maximum: QConfigured inclusive point maximum.
Insufficient
A cumulative consumption request exceeded the remaining capacity.
Implementations§
Source§impl<R, Q> BudgetError<R, Q>
impl<R, Q> BudgetError<R, Q>
Sourcepub const fn resource(&self) -> &R
pub const fn resource(&self) -> &R
Returns the resource associated with this failure.
§Returns
Returns the resource associated with this failure.
Sourcepub fn into_resource(self) -> R
pub fn into_resource(self) -> R
Consumes this error and returns its associated resource.
§Returns
Consumes this error and returns its associated resource.
Sourcepub const fn limit(&self) -> Option<Q>
pub const fn limit(&self) -> Option<Q>
Returns the cumulative limit for budget and pool failures.
Returns Some(limit) for Self::Insufficient, or None for a
point-limit failure.
§Returns
Returns the cumulative limit for budget and pool failures.
Sourcepub const fn observation(&self) -> Option<Observation<Q>>
pub const fn observation(&self) -> Option<Observation<Q>>
Returns the observation for a point-limit failure.
Returns Some(observed) for Self::LimitExceeded, or None for a
cumulative-budget or pool failure.
§Returns
Returns the observation for a point-limit failure.
Sourcepub const fn exact_observed(&self) -> Option<Q>
pub const fn exact_observed(&self) -> Option<Q>
Returns the exact point measurement when the observation is exact.
§Returns
Returns the exact point measurement when the observation is exact.
None indicates that the observation is only a lower bound.
Sourcepub const fn observed_lower_bound(&self) -> Option<Q>
pub const fn observed_lower_bound(&self) -> Option<Q>
Returns the safe lower bound of a point measurement.
§Returns
Returns the safe lower bound of a point measurement.
None indicates that this is a cumulative-budget failure rather than a
point-limit failure.
Sourcepub const fn maximum(&self) -> Option<Q>
pub const fn maximum(&self) -> Option<Q>
Returns the configured maximum for a point-limit failure.
Returns Some(maximum) for Self::LimitExceeded, or None for a
cumulative-budget or pool failure.
§Returns
Returns the configured maximum for a point-limit failure.
Sourcepub const fn remaining(&self) -> Option<Q>
pub const fn remaining(&self) -> Option<Q>
Returns the remaining capacity for a cumulative-budget failure.
Returns Some(remaining) for Self::Insufficient, including failed
pool acquisitions, or None for a point-limit failure.
§Returns
Returns the remaining capacity for a cumulative-budget failure.
Sourcepub const fn requested(&self) -> Option<Q>
pub const fn requested(&self) -> Option<Q>
Returns the requested quantity for a cumulative budget failure.
Returns Some(requested) for Self::Insufficient, or None for a
point-limit failure.
§Returns
Returns the requested quantity for a cumulative budget failure.
Source§impl<R, Q> BudgetError<R, Q>where
Q: ResourceQuantity,
impl<R, Q> BudgetError<R, Q>where
Q: ResourceQuantity,
Sourcepub const fn configured_limit(&self) -> Q
pub const fn configured_limit(&self) -> Q
Returns the configured limit for either point or cumulative failures.
§Returns
Returns the configured limit for either point or cumulative failures.
Trait Implementations§
Source§impl<R: Clone, Q> Clone for BudgetError<R, Q>
impl<R: Clone, Q> Clone for BudgetError<R, Q>
Source§fn clone(&self) -> BudgetError<R, Q>
fn clone(&self) -> BudgetError<R, Q>
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, Q> Debug for BudgetError<R, Q>
impl<R: Debug, Q> Debug for BudgetError<R, Q>
Source§impl<R, Q> Display for BudgetError<R, Q>
impl<R, Q> Display for BudgetError<R, Q>
impl<R: Eq, Q> Eq for BudgetError<R, Q>
Source§impl<R, Q> Error for BudgetError<R, Q>
impl<R, Q> Error for BudgetError<R, Q>
1.30.0 · 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()