Struct NoticeQueue

Source
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>

Source

pub fn new() -> NoticeQueue<N, T, K>

Empty, reusable storage. Zero capacity is supported and rejects all input.

Source

pub const fn capacity(&self) -> usize

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn front(&self) -> Option<NoticeView<'_, T, K>>

Highest priority, oldest entry at that priority; no visibility side effect.

Source

pub fn iter(&self) -> impl ExactSizeIterator

All entries in presentation order, including ones a host chooses to hide.

Source

pub fn pop_front(&mut self) -> Option<Notice<T, K>>

Remove the front notice without dropping its payload, including unkeyed text.

Source

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

pub fn clear(&mut self)

Drop all transient entries on restart, reusing the same inline storage. No key or remaining lifetime survives reset. The queue owns no accumulated clock, arrival counter or external event history.

Source§

impl<const N: usize, T, K> NoticeQueue<N, T, K>
where K: Eq,

Source

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());
Source

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.

Source

pub fn dismiss(&mut self, key: &K) -> Option<Notice<T, K>>

Remove a keyed notice, returning ownership. A stale/missing key is a no-op.

Trait Implementations§

Source§

impl<const N: usize, T, K> Debug for NoticeQueue<N, T, K>
where T: Debug, K: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<const N: usize, T, K> Default for NoticeQueue<N, T, K>

Source§

fn default() -> NoticeQueue<N, T, K>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize, T, K> Freeze for NoticeQueue<N, T, K>
where T: Freeze, K: Freeze,

§

impl<const N: usize, T, K> RefUnwindSafe for NoticeQueue<N, T, K>

§

impl<const N: usize, T, K> Send for NoticeQueue<N, T, K>
where T: Send, K: Send,

§

impl<const N: usize, T, K> Sync for NoticeQueue<N, T, K>
where T: Sync, K: Sync,

§

impl<const N: usize, T, K> Unpin for NoticeQueue<N, T, K>
where T: Unpin, K: Unpin,

§

impl<const N: usize, T, K> UnwindSafe for NoticeQueue<N, T, K>
where T: UnwindSafe, K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.