pub struct SessionBudget {
pub session_id: u64,
pub budgets: HashMap<ResourceType, Budget>,
}Expand description
Per-session budget container. Holds one Budget per ResourceType.
Fields§
§session_id: u64Unique identifier for the owning session.
budgets: HashMap<ResourceType, Budget>Per-resource budgets.
Implementations§
Source§impl SessionBudget
impl SessionBudget
Sourcepub fn new(session_id: u64, limits: Vec<(ResourceType, u64)>) -> Self
pub fn new(session_id: u64, limits: Vec<(ResourceType, u64)>) -> Self
Create a new session budget with pre-defined limits.
Resources not listed in limits will be auto-created on first use
with a limit of u64::MAX.
Sourcepub fn consume(
&mut self,
resource: ResourceType,
amount: u64,
) -> Result<(), String>
pub fn consume( &mut self, resource: ResourceType, amount: u64, ) -> Result<(), String>
Consume amount units of resource.
§Errors
Returns Err("budget exceeded") if the consumption would push used
past limit. The budget is not modified in that case.
If no budget exists for resource, one is auto-created with
limit = u64::MAX before the consumption is applied.
Sourcepub fn remaining(&self, resource: ResourceType) -> u64
pub fn remaining(&self, resource: ResourceType) -> u64
Remaining units for resource.
Returns u64::MAX when the resource has not been registered (no
limit has been set — it is effectively unlimited).
Sourcepub fn is_any_exhausted(&self) -> bool
pub fn is_any_exhausted(&self) -> bool
Whether any registered resource is exhausted.
Trait Implementations§
Source§impl Clone for SessionBudget
impl Clone for SessionBudget
Source§fn clone(&self) -> SessionBudget
fn clone(&self) -> SessionBudget
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SessionBudget
impl RefUnwindSafe for SessionBudget
impl Send for SessionBudget
impl Sync for SessionBudget
impl Unpin for SessionBudget
impl UnsafeUnpin for SessionBudget
impl UnwindSafe for SessionBudget
Blanket Implementations§
impl<T> Allocation for T
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
Converts
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>
Converts
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