pub struct EventLog { /* private fields */ }Expand description
A bounded log that drops the oldest record when full.
use hardless_core::{EventKind, EventLog, EventRecord, Millis};
let mut log = EventLog::new(2);
for seq in 1..=3 {
log.push(EventRecord { seq, at: Millis(0), device_id: "d".parse().unwrap(), kind: EventKind::Reset });
}
assert_eq!(log.iter().map(|r| r.seq).collect::<Vec<_>>(), [2, 3]);Implementations§
Source§impl EventLog
impl EventLog
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
An empty log holding at most capacity records (at least one).
Sourcepub fn push(&mut self, record: EventRecord)
pub fn push(&mut self, record: EventRecord)
Appends a record, dropping the oldest if the log is full.
Sourcepub fn iter(
&self,
) -> impl DoubleEndedIterator<Item = &EventRecord> + ExactSizeIterator
pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = &EventRecord> + ExactSizeIterator
Records oldest first.
Sourcepub fn since(&self, since: u64) -> impl Iterator<Item = &EventRecord>
pub fn since(&self, since: u64) -> impl Iterator<Item = &EventRecord>
Records with seq greater than since, oldest first.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EventLog
impl RefUnwindSafe for EventLog
impl Send for EventLog
impl Sync for EventLog
impl Unpin for EventLog
impl UnsafeUnpin for EventLog
impl UnwindSafe for EventLog
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