pub struct BudgetHandle { /* private fields */ }Expand description
One turn’s budget, started when its message arrived. Cheap to clone; the clones share one account.
Implementations§
Source§impl BudgetHandle
impl BudgetHandle
Sourcepub fn start(budget: &Budget) -> BudgetHandle
pub fn start(budget: &Budget) -> BudgetHandle
Starts the account of budget now: the deadline is now plus its
time, each meter starts unspent.
Sourcepub fn start_at(budget: &Budget, received: Instant) -> BudgetHandle
pub fn start_at(budget: &Budget, received: Instant) -> BudgetHandle
Starts the account of budget as if it arrived at received.
Sourcepub fn remaining_time(&self) -> Option<Duration>
pub fn remaining_time(&self) -> Option<Duration>
The time left, or None when the budget sets no deadline.
Sourcepub fn remaining(&self, meter: &str) -> Option<u64>
pub fn remaining(&self, meter: &str) -> Option<u64>
What is left of meter, or None when the budget does not name it
(it is then unlimited).
Sourcepub fn charge(&self, meter: &str, amount: u64) -> Result<Option<u64>, Exhausted>
pub fn charge(&self, meter: &str, amount: u64) -> Result<Option<u64>, Exhausted>
Records amount of real spend on meter and returns what is left.
The spend is recorded whatever the result, because it already
happened; refusing it would lose the record. A meter the budget does
not name is unlimited and charging it records nothing (Ok(None)).
§Errors
Exhausted::Meter once the meter is overdrawn, with the overdraft.
Sourcepub fn status(&self) -> BudgetStatus
pub fn status(&self) -> BudgetStatus
What is left and spent, for the task’s metadata. spent includes
what is reserved for children not yet settled.
No number in it is more than 2^53, the largest a protobuf number (a
double, which is what metadata is over gRPC) holds exactly: the status
is written onto every status update, and the server refuses an event
that holds a larger one, the one that ends the task included. A
provider can report any u64 as its usage and a child any u64 as its
spend, so the account can hold more; the status then says “at least
this much”, at that largest number.
Sourcepub fn grant(&self, request: &Budget) -> Result<ChildGrant, Exhausted>
pub fn grant(&self, request: &Budget) -> Result<ChildGrant, Exhausted>
Carves a child’s budget out of this one, as request asks.
- Time: the smaller of the request’s and what is left here less
a reserve (5% of what is left, from
MIN_GRANT_RESERVEtoMAX_GRANT_RESERVE). - Meters: each meter this budget names goes to the child as the
smaller of the request and what is left, and is reserved here at
once, so many children cannot each be given the whole. One the
request does not name goes as 0: a child cannot spend outside this
budget by omission. One only the request names passes through, as
this budget does not limit it (at most 2^53, the largest number the
child’s server accepts in a message’s metadata), while the child has fewer than
MAX_METERS; beyond that it is left out, since a child’s server refuses more.
§Errors
Exhausted when less than a millisecond is left after the reserve
(or asked for), or a meter the request names with a non-zero amount
is empty here. Nothing is reserved then. A request that names no
meter succeeds on an exhausted budget, granting its meters as 0.
Trait Implementations§
Source§impl Clone for BudgetHandle
impl Clone for BudgetHandle
Source§fn clone(&self) -> BudgetHandle
fn clone(&self) -> BudgetHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Forget for BudgetHandle
impl Freeze for BudgetHandle
impl Move for BudgetHandle
impl RefUnwindSafe for BudgetHandle
impl Send for BudgetHandle
impl Sync for BudgetHandle
impl Unpin for BudgetHandle
impl UnsafeUnpin for BudgetHandle
impl UnwindSafe for BudgetHandle
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].