#[non_exhaustive]pub enum Decision {
Acquired,
Retry {
after: Duration,
},
Impossible,
}Expand description
What happened when a limiter was asked for tokens without waiting.
This is the synchronous core that the waiting
acquire surface is built on, and the value the
Limiter trait returns so composite limiters can reason
about an outcome before deciding whether to wait. The waiting layer maps it
to either a return, a sleep, or a ThrottleError.
#[non_exhaustive]: later phases add outcomes (for example, a deadline or a
circuit-open signal), so a match on it must include a wildcard arm.
§Examples
use std::time::Duration;
use throttle_net::Decision;
// Granted now:
assert!(Decision::Acquired.is_acquired());
// Refused for now, retry after the wait:
let d = Decision::Retry { after: Duration::from_millis(20) };
assert_eq!(d.retry_after(), Some(Duration::from_millis(20)));
// Can never succeed (cost exceeds capacity):
assert!(!Decision::Impossible.is_acquired());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Acquired
The tokens were granted and have been deducted.
Retry
The request was refused for now. The bucket will hold enough tokens
again after after has elapsed, assuming no competing acquisitions.
Impossible
The request can never succeed: the cost exceeds the limiter’s capacity, so no amount of waiting will satisfy it.
Implementations§
Source§impl Decision
impl Decision
Sourcepub const fn is_acquired(&self) -> bool
pub const fn is_acquired(&self) -> bool
Returns true if the tokens were granted.
§Examples
use throttle_net::Decision;
assert!(Decision::Acquired.is_acquired());
assert!(!Decision::Impossible.is_acquired());Sourcepub const fn retry_after(&self) -> Option<Duration>
pub const fn retry_after(&self) -> Option<Duration>
Returns the wait before a retry can succeed, or None when the request
was granted or is impossible.
§Examples
use std::time::Duration;
use throttle_net::Decision;
let d = Decision::Retry { after: Duration::from_millis(20) };
assert_eq!(d.retry_after(), Some(Duration::from_millis(20)));
assert_eq!(Decision::Acquired.retry_after(), None);