pub struct IncrementalCounts { /* private fields */ }Expand description
A running tally of the gh records logged since a fixed instant, refreshed
by reading only what was appended since the previous refresh.
Equivalent to aggregate over [since, ∞), minus the
cost: construction reads no records, and each refresh
reads only the complete lines appended after the last one. A line still being
written (no trailing newline yet) is left for the next refresh, so a record is
counted once, whole. That is the one way the two differ over the same bytes:
aggregate counts a final line with no newline if it happens to parse, this
waits for the newline.
Implementations§
Source§impl IncrementalCounts
impl IncrementalCounts
Sourcepub fn start(path: PathBuf) -> Self
pub fn start(path: PathBuf) -> Self
Starts tallying the log at path from now: records already in it are
never read, and the tally begins at zero.
The log’s extent is taken before the clock is read. A record stamped at
or after since was therefore appended after the baseline,
so the bytes the next refresh reads contain every record the window
admits. Reading them in the other order could skip a record stamped just
after the clock read but appended before the baseline.
Sourcepub fn since(&self) -> DateTime<Utc>
pub fn since(&self) -> DateTime<Utc>
The instant the window opened: records stamped before it are not counted.
Sourcepub fn refresh(&mut self, stop: impl FnMut() -> bool) -> bool
pub fn refresh(&mut self, stop: impl FnMut() -> bool) -> bool
Reads the records appended since the last call into the tally.
stop is checked before every line; once it returns true the refresh
ends there, leaving the tally and cursor consistent at that line, so the
next refresh resumes without losing or repeating anything. It is how a
caller on a blocking thread — which cannot be cancelled from outside —
gives up on a long read, e.g. the rebuild after the log was replaced.
Returns true when the tally is current as of the last complete line, and
false when it may be behind: stop fired, or the log could not be read
(logged at debug; best-effort like the rest of the log stack).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for IncrementalCounts
impl RefUnwindSafe for IncrementalCounts
impl Send for IncrementalCounts
impl Sync for IncrementalCounts
impl Unpin for IncrementalCounts
impl UnsafeUnpin for IncrementalCounts
impl UnwindSafe for IncrementalCounts
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
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