pub struct Spend {
pub tokens: u64,
pub minor_units: u64,
}Expand description
What one effect consumed.
Deliberately unit-agnostic: the engine never learns what a token is or which
currency minor_units is in. It adds them up and compares them to a limit.
Fields§
§tokens: u64Model tokens, or any other metered unit the deployment counts.
minor_units: u64Money in minor units — cents, pence, whatever the deployment uses.
Integer rather than float: money that rounds differently on two machines is money that produces two different budget verdicts.
Unsigned, and that is a security property rather than tidiness. Every
ceiling in this crate — a Budget, a TenantQuota, a
StandingAuthority — is enforced by comparing an accumulated Spend
against a limit. A negative amount reverses the accumulation, so a
single one un-spends everything before it and the ceiling stops being
one. That was reachable while this was an i64: a €500 standing
authority could be drawn to zero, drawn again for −€400, and then drawn
for a further €400 — €900 against a €500 mandate, with every check
passing. Refusing negatives in each of the three enforcement paths would
have been three places to remember; making the state unrepresentable is
none.
A refund or a credit is therefore not a Spend. It is a new
authorization, which is what leaves both decisions on the record.
Implementations§
Source§impl Spend
impl Spend
pub const fn tokens(n: u64) -> Self
pub const fn money(minor_units: u64) -> Self
Sourcepub const fn is_free_ref(v: &Self) -> bool
pub const fn is_free_ref(v: &Self) -> bool
By-reference form, for skip_serializing_if.
One predicate under one name. Two spellings of “did this cost
anything” is two places for the answer to drift, and the by-reference
form exists only because skip_serializing_if hands out a reference.
Trait Implementations§
Source§impl AddAssign for Spend
impl AddAssign for Spend
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreimpl Copy for Spend
Source§impl<'de> Deserialize<'de> for Spend
impl<'de> Deserialize<'de> for Spend
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Spend
What it cost, in a sentence a person reads.
impl Display for Spend
What it cost, in a sentence a person reads.
This type reaches operators through refusals — a standing authority short of
what a draw asked for names both amounts — where {:?} puts Rust syntax in
the middle of an English sentence. A zero is still printed: it says the
other dimension was unspent, where omitting it leaves a reader to guess
whether it was unmetered.
impl Eq for Spend
impl StructuralPartialEq for Spend
Auto Trait Implementations§
impl Freeze for Spend
impl RefUnwindSafe for Spend
impl Send for Spend
impl Sync for Spend
impl Unpin for Spend
impl UnsafeUnpin for Spend
impl UnwindSafe for Spend
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
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> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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