pub struct MeterStore { /* private fields */ }Expand description
Append-only local JSONL store.
Implementations§
Source§impl MeterStore
impl MeterStore
pub fn new(data_dir: impl AsRef<Path>) -> Self
pub fn from_data_dir() -> Result<Self, String>
pub fn path(&self) -> &Path
Sourcepub fn append(&self, entry: &MeterEntry) -> Result<(), String>
pub fn append(&self, entry: &MeterEntry) -> Result<(), String>
Appends one complete JSON object and newline. Call this only off the hot path.
Sourcepub fn append_best_effort(entry: MeterEntry)
pub fn append_best_effort(entry: MeterEntry)
Schedules persistence and returns immediately; metering cannot delay a tool call.
pub fn aggregate(&self) -> MeterAggregate
Sourcepub fn day_totals(&self, day: NaiveDate) -> DayTotals
pub fn day_totals(&self, day: NaiveDate) -> DayTotals
Totals for the UTC day day. The file is append-only and chronological and
grows to tens of MB, so it is read backwards and parsing stops at the first
earlier entry: the cost follows the day’s volume, not the history.
Sourcepub fn day_totals_where(
&self,
day: NaiveDate,
keep: impl Fn(Option<&str>) -> bool,
) -> DayTotals
pub fn day_totals_where( &self, day: NaiveDate, keep: impl Fn(Option<&str>) -> bool, ) -> DayTotals
Self::day_totals over the entries whose project key keep accepts.
Trait Implementations§
Source§impl Clone for MeterStore
impl Clone for MeterStore
Auto Trait Implementations§
impl Freeze for MeterStore
impl RefUnwindSafe for MeterStore
impl Send for MeterStore
impl Sync for MeterStore
impl Unpin for MeterStore
impl UnsafeUnpin for MeterStore
impl UnwindSafe for MeterStore
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
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<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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