pub struct NotificationLog {
capacity: usize,
entries: VecDeque<Notification>,
}Expand description
In-memory ring buffer for in-app notifications.
Entries are stored in insertion order. When the buffer is full the oldest entry is evicted before the new one is appended (ring semantics).
All public methods are &mut self; callers must hold the RwLock write
guard from NotificationLogHandle when mutating.
Fields§
§capacity: usize§entries: VecDeque<Notification>Entries stored in insertion order (oldest first).
Implementations§
Source§impl NotificationLog
impl NotificationLog
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a log with a custom capacity. A capacity of 0 is clamped to 1.
Sourcepub fn push(&mut self, notification: Notification)
pub fn push(&mut self, notification: Notification)
Append a notification. If the buffer is at capacity the oldest entry is dropped first.
Sourcepub fn push_with_broadcast<E: EventEmitter>(
&mut self,
notification: Notification,
channel: &E,
) -> Result<(), AppError>
pub fn push_with_broadcast<E: EventEmitter>( &mut self, notification: Notification, channel: &E, ) -> Result<(), AppError>
Append a notification and emit a NotificationNew event via
channel. Errors from the emit are returned but the notification is
always stored (emit failure is non-fatal in the log itself).
Sourcepub fn list(&self, since: Option<i64>) -> Vec<Notification>
pub fn list(&self, since: Option<i64>) -> Vec<Notification>
Return all notifications with timestamp >= since_ms, or all entries
when since_ms is None.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NotificationLog
impl RefUnwindSafe for NotificationLog
impl Send for NotificationLog
impl Sync for NotificationLog
impl Unpin for NotificationLog
impl UnsafeUnpin for NotificationLog
impl UnwindSafe for NotificationLog
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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