pub struct SpendKey {
pub org: String,
pub agent: Option<String>,
pub vendor: Option<String>,
pub period: SpendPeriod,
}Expand description
Names a scope of spend and the window it is summed over.
org is required. agent and vendor narrow the scope; None means “any”. Passed
to SpendLedger::reserve, the key attributes the spend, and its None fields
record the spend as unattributed on that dimension. Used as a limit, the key bounds
every entry it covers within its period.
§Example
use adk_core::{SpendKey, SpendPeriod};
let gemini_daily = SpendKey::org("acme").with_vendor("gemini").per(SpendPeriod::Day);
let call = SpendKey::org("acme").with_agent("researcher").with_vendor("gemini");
assert!(gemini_daily.covers(&call));
assert!(!gemini_daily.covers(&SpendKey::org("acme").with_vendor("openai")));Fields§
§org: StringOrganization, tenant, or application the spend belongs to.
agent: Option<String>Agent that spent, or None for any agent.
vendor: Option<String>Vendor paid (model provider or merchant), or None for any vendor.
period: SpendPeriodWindow the key sums over when used as a limit.
Implementations§
Source§impl SpendKey
impl SpendKey
Sourcepub fn org(org: impl Into<String>) -> Self
pub fn org(org: impl Into<String>) -> Self
Creates a key for all of org’s spend over SpendPeriod::Lifetime.
Sourcepub fn with_agent(self, agent: impl Into<String>) -> Self
pub fn with_agent(self, agent: impl Into<String>) -> Self
Narrows the key to one agent.
Sourcepub fn with_vendor(self, vendor: impl Into<String>) -> Self
pub fn with_vendor(self, vendor: impl Into<String>) -> Self
Narrows the key to one vendor.
Sourcepub fn per(self, period: SpendPeriod) -> Self
pub fn per(self, period: SpendPeriod) -> Self
Sets the window the key sums over.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SpendKey
impl<'de> Deserialize<'de> for SpendKey
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for SpendKey
impl StructuralPartialEq for SpendKey
Auto Trait Implementations§
impl Forget for SpendKey
impl Freeze for SpendKey
impl Move for SpendKey
impl RefUnwindSafe for SpendKey
impl Send for SpendKeywhere
RawVecInner: Send,
impl Sync for SpendKeywhere
RawVecInner: Sync,
impl Unpin for SpendKey
impl UnsafeUnpin for SpendKey
impl UnwindSafe for SpendKeywhere
RawVecInner: UnwindSafe,
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
Mutably borrows from an owned value. Read more