pub struct NoticeQueue<const N: usize, T, K = u64> { /* private fields */ }Expand description
Fixed inline storage with stable descending-priority presentation order.
Equal priorities retain arrival order. At saturation, an incoming notice can evict only a strictly lower priority: the oldest entry at the lowest priority is evicted first. Existing critical entries survive unrelated bursts, even critical bursts. Keyed replacement explicitly bypasses that rule and counts as a new arrival. Coalescing keeps the original key/specification, promotes priority to the larger value, and keeps its place unless promoted; promotion joins behind existing entries of the new priority.
Submission/removal use O(N) queue work and O(1) additional storage, excluding
caller equality, merge and destructor work. Expiring multiple entries can
take O(N²) work because each removal preserves order before disposal. Clear
is O(N). No Clone, Default or Copy bound is required for messages or keys.
Choose N/payload sizes to suit stack limits. Timing uses ordinary f64
arithmetic: deltas below the representable precision may not reduce a large
remaining lifetime; no cross-platform bitwise determinism is promised.
§Panic and disposal boundaries
Equality and merge callbacks run before structural mutation; a panic leaves
queue metadata unchanged. Interior mutation/side effects in caller code are
not rolled back. Coalescing receives shared references, returns a new payload
and returns both discarded inputs to the host. advance, clear, dropping
the queue, and dropping returned values can execute caller destructors.
A destructor panic is not transactional: earlier changes remain, later work
may be incomplete. Removed slots are detached/compacted before disposal, so
storage/length remain valid. Destructors must not panic for normal use.
Implementations§
Source§impl<const N: usize, T, K> NoticeQueue<N, T, K>
impl<const N: usize, T, K> NoticeQueue<N, T, K>
Sourcepub fn new() -> NoticeQueue<N, T, K>
pub fn new() -> NoticeQueue<N, T, K>
Empty, reusable storage. Zero capacity is supported and rejects all input.
pub const fn capacity(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn front(&self) -> Option<NoticeView<'_, T, K>>
pub fn front(&self) -> Option<NoticeView<'_, T, K>>
Highest priority, oldest entry at that priority; no visibility side effect.
Sourcepub fn iter(&self) -> impl ExactSizeIterator
pub fn iter(&self) -> impl ExactSizeIterator
All entries in presentation order, including ones a host chooses to hide.
Sourcepub fn pop_front(&mut self) -> Option<Notice<T, K>>
pub fn pop_front(&mut self) -> Option<Notice<T, K>>
Remove the front notice without dropping its payload, including unkeyed text.
Sourcepub fn advance(&mut self, delta_seconds: f64) -> Result<usize, NoticeTimeError>
pub fn advance(&mut self, delta_seconds: f64) -> Result<usize, NoticeTimeError>
Age every entry by explicit finite, nonnegative seconds. Zero is a no-op; a delta reaching/exceeding remaining lifetime expires and drops the entry. Subtraction clamps at zero without overflow. Returns the number expired. Hidden entries expire too; no total wall time is accumulated.
Source§impl<const N: usize, T, K> NoticeQueue<N, T, K>where
K: Eq,
impl<const N: usize, T, K> NoticeQueue<N, T, K>where
K: Eq,
Sourcepub fn insert(
&mut self,
notice: Notice<T, K>,
duplicate: NoticeDuplicate,
) -> Result<NoticeChange<T, K>, NoticeRejected<T, K>>
pub fn insert( &mut self, notice: Notice<T, K>, duplicate: NoticeDuplicate, ) -> Result<NoticeChange<T, K>, NoticeRejected<T, K>>
Insert or apply an explicit duplicate-key policy. All lifetimes are validated before key matching, including when keeping an existing entry.
use ferravex_play::ui::notices::{
Notice, NoticeDuplicate, NoticePriority, NoticeQueue,
};
let mut notices = NoticeQueue::<2, &str, &str>::new();
notices.insert(Notice {
key: Some("objective"), priority: NoticePriority::High,
message: "Altar I awakened. The second altar is ready.",
lifetime_seconds: 3.5,
}, NoticeDuplicate::Replace).unwrap(); // After objective acceptance.
assert_eq!(notices.capacity(), 2);
assert_eq!(notices.iter().len(), 1);
assert_eq!(notices.pop_front().unwrap().key, Some("objective"));
assert!(notices.is_empty());Sourcepub fn coalesce_with(
&mut self,
notice: Notice<T, K>,
lifetime: NoticeLifetime,
merge: impl FnOnce(&T, &T) -> T,
) -> Result<NoticeChange<T, K>, NoticeRejected<T, K>>
pub fn coalesce_with( &mut self, notice: Notice<T, K>, lifetime: NoticeLifetime, merge: impl FnOnce(&T, &T) -> T, ) -> Result<NoticeChange<T, K>, NoticeRejected<T, K>>
Merge matching payloads using caller arithmetic/overflow policy. Missing
keys follow ordinary insertion/saturation, without invoking merge.
Invalid lifetimes also skip the callback. No payload is cloned or dropped
internally. Key equality/merge panics occur before queue mutation.