latch-billing - Pure synchronous token billing core library.
This crate defines the core types, traits, and pricing models for token-based billing. It is purely synchronous and has zero I/O dependencies.
Architecture
- Types:
UsageObservation,MeterSet,BillingSubject, etc. - Traits:
PricingSource,RatingEngine,ObservationStore,RatedRecordStore,RatedRecordExporter,QuotaAuthorizer, etc. - Design principle: Runtime-agnostic sync library. Async I/O should be implemented by downstream consumers (e.g., gateway applications).
Quick start
use *;
// 1. Create an observation
let mut meter_set = new;
meter_set.accumulate.unwrap;
let observation = UsageObservation ;
// 2. Get a price snapshot (push mode - caller fethes)
let snapshot = ...; // fetched by caller (e.e., from DB)
// 3. Create rating context (for tier-based pricing)
let context = default;
// 4. Rate the observation
let engine = new;
let rated = engine.rate?;
println!;
Module structure
observation:UsageObservation,MeterSet,MeterKind,UsageSource,UsageOutcome,Attributesidentity:BillingSubject,UsageEventId,UsageEventIdBuilder,CorrelationIdspricing:ModelRef,ProviderRef,PriceSnapshot,PricingSourcetrait,TierConfig,TierBaselinerating:RatedUsageRecord,RatingResult,RatedLineItem,RatingEnginetrait,RatingContextstorage:ObservationStoretrait,RatedRecordStoretrait,StoreResultquota:QuotaAuthorizertrait,QuotaReservatortrait (Phase 2)export:RatedRecordExportertrait