pub struct IterationBudget { /* private fields */ }Expand description
Per-surface iteration budget. Counts agent-driven patches per
surface; once a surface hits the cap, the handler short-circuits
the agent entirely until the surface is reset (typically via
delete_surface + create_surface, or an explicit reset).
The budget is in-memory: a single-process daemon keeps its
counters for the lifetime of the process. A durable backend
using car-state::StateStore::durable is a v2 — the runtime’s
transient strategy library doesn’t yet justify persisting
iteration counts across restarts.
Implementations§
Source§impl IterationBudget
impl IterationBudget
pub fn new() -> Self
pub fn with_max(max: u32) -> Self
Sourcepub fn try_consume(&self, surface_id: &str) -> bool
pub fn try_consume(&self, surface_id: &str) -> bool
Atomic check-and-increment. Returns true when the surface
had budget AND the count has been bumped to claim it;
false when the surface is at the cap and the caller must
skip the agent invocation. The two steps happen under
DashMap’s per-shard lock so concurrent reports for the same
surface can’t both pass at count = max - 1.
Pairs with refund for the failed-apply path: the budget
is consumed up-front; if the patch apply errors, the
handler calls refund to release the slot. That keeps the
“budget reflects successful applies” invariant while
eliminating the original has_budget + record_apply race.
Sourcepub fn refund(&self, surface_id: &str)
pub fn refund(&self, surface_id: &str)
Release a budget slot consumed by try_consume when the
downstream apply turned out to fail. Saturates at zero so a
stray refund without a matching consume can’t drive the
counter negative.
Sourcepub fn reset(&self, surface_id: &str)
pub fn reset(&self, surface_id: &str)
Clear the surface’s counter. Surface recreation triggers this via the caller; the loop is allowed to start over.
Sourcepub fn count(&self, surface_id: &str) -> u32
pub fn count(&self, surface_id: &str) -> u32
Current iteration count for a surface. Public so the hard-stop log can include it.
pub fn max(&self) -> u32
Trait Implementations§
Auto Trait Implementations§
impl Freeze for IterationBudget
impl !RefUnwindSafe for IterationBudget
impl Send for IterationBudget
impl Sync for IterationBudget
impl Unpin for IterationBudget
impl UnsafeUnpin for IterationBudget
impl UnwindSafe for IterationBudget
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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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