pub struct RateLease {
pub effect: String,
pub limit: i64,
pub period: BudgetPeriod,
/* private fields */
}Expand description
One quota’s live state: a refilling bucket (rate:) or a fixed window
(max:). Construct via RateLease::rate / RateLease::max /
RateLease::from_quota. Consume via RateLease::try_acquire.
Fields§
§effect: StringThe declared tool this quota governs (on Tool(effect)).
limit: i64The token allowance per period (> 0).
period: BudgetPeriodThe renewal/window period.
Implementations§
Source§impl RateLease
impl RateLease
Sourcepub fn rate(
effect: impl Into<String>,
limit: i64,
period: BudgetPeriod,
now: DateTime<Utc>,
) -> Self
pub fn rate( effect: impl Into<String>, limit: i64, period: BudgetPeriod, now: DateTime<Utc>, ) -> Self
A rate: quota — a token bucket starting FULL (limit tokens), refilling
limit tokens per period.
Sourcepub fn max(
effect: impl Into<String>,
limit: i64,
period: BudgetPeriod,
now: DateTime<Utc>,
) -> Self
pub fn max( effect: impl Into<String>, limit: i64, period: BudgetPeriod, now: DateTime<Utc>, ) -> Self
A max: quota — a fixed window of period, starting empty (0 consumed).
Sourcepub fn from_quota(q: &IRBudgetQuota, now: DateTime<Utc>) -> Option<Self>
pub fn from_quota(q: &IRBudgetQuota, now: DateTime<Utc>) -> Option<Self>
Build a lease from a compiled IRBudgetQuota. None if the period is
not in the closed catalog (the type checker prevents this for compiled
programs; the caller fail-closes defensively).
Sourcepub fn refill(&mut self, now: DateTime<Utc>)
pub fn refill(&mut self, now: DateTime<Utc>)
Bring the lease current as of now (refill the bucket / roll the window).
Idempotent at a fixed now; pure given the prior state.
Sourcepub fn try_acquire(&mut self, now: DateTime<Utc>) -> AcquireOutcome
pub fn try_acquire(&mut self, now: DateTime<Utc>) -> AcquireOutcome
Attempt to consume one token as of now. Refills/rolls first, then either
consumes (→ AcquireOutcome::Granted) or denies with the next-available
instant. PURE: same (state, now) ⇒ same outcome + same post-state.
Sourcepub fn available(&self, now: DateTime<Utc>) -> f64
pub fn available(&self, now: DateTime<Utc>) -> f64
The number of tokens currently available (after refilling to now).
Whole tokens for a window; fractional for a bucket.
Sourcepub fn peek(&self, now: DateTime<Utc>) -> AcquireOutcome
pub fn peek(&self, now: DateTime<Utc>) -> AcquireOutcome
Whether a token is available at now WITHOUT consuming it. Granted if a
call would succeed; Denied{retry_at} otherwise. Used by the multi-quota
gate to test all-or-none before committing any consumption.
Sourcepub fn snapshot(&self) -> RateLeaseSnapshot
pub fn snapshot(&self) -> RateLeaseSnapshot
§Fase 72.e — capture this lease’s live STATE as a serializable snapshot
(epoch-millis, no chrono in the wire form). The enterprise daemon
supervisor persists it so a max window / rate bucket is cumulative
ACROSS ticks (a daily cap spans the day’s ticks). The §52 fire-once claim
serializes a daemon’s ticks, so load → run → save needs no lock.
Sourcepub fn restore(&mut self, snap: &RateLeaseSnapshot)
pub fn restore(&mut self, snap: &RateLeaseSnapshot)
§Fase 72.e — restore this lease’s STATE from a snapshot (the inverse of
snapshot). A kind mismatch (a rate lease restored
from a max snapshot — e.g. the budget grammar changed between ticks) is
IGNORED, leaving the freshly-built state (fail-safe: a re-budgeted daemon
starts clean rather than mis-restoring).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RateLease
impl RefUnwindSafe for RateLease
impl Send for RateLease
impl Sync for RateLease
impl Unpin for RateLease
impl UnsafeUnpin for RateLease
impl UnwindSafe for RateLease
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more