pub struct BrainWaveTracker {
pub config: BrainWaveConfig,
/* private fields */
}Expand description
Tracks event timestamps and computes the current brain-wave state.
Uses a ring buffer of timestamps — no extra thread, no polling. Update is ~10ns (atomic push to ring buffer).
Fields§
§config: BrainWaveConfigConfiguration for state transitions
Implementations§
Source§impl BrainWaveTracker
impl BrainWaveTracker
Sourcepub fn new(config: BrainWaveConfig) -> Self
pub fn new(config: BrainWaveConfig) -> Self
Create a new tracker with the given config.
Sourcepub fn record_event(&mut self) -> BrainWave
pub fn record_event(&mut self) -> BrainWave
Record an event and update the brain-wave state.
Sourcepub fn recompute(&mut self, now: Instant) -> BrainWave
pub fn recompute(&mut self, now: Instant) -> BrainWave
Recompute the current state without recording an event. Called when checking state after a timer fires.
Sourcepub fn next_transition_duration(&self) -> Duration
pub fn next_transition_duration(&self) -> Duration
Compute how long to sleep before the next state transition would occur.
Returns Duration::MAX if no transition is pending (e.g., Delta with
no scheduled tasks). The caller should use this in a tokio::select!
branch alongside stdin readiness.
Sourcepub fn idle_duration(&self) -> Duration
pub fn idle_duration(&self) -> Duration
Time since the last event was recorded.
Auto Trait Implementations§
impl Freeze for BrainWaveTracker
impl RefUnwindSafe for BrainWaveTracker
impl Send for BrainWaveTracker
impl Sync for BrainWaveTracker
impl Unpin for BrainWaveTracker
impl UnsafeUnpin for BrainWaveTracker
impl UnwindSafe for BrainWaveTracker
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