Skip to main content

PriorityQueue

Struct PriorityQueue 

Source
pub struct PriorityQueue { /* private fields */ }
Expand description

Priority queue for events.

Maintains events in priority order with FIFO ordering for events of the same priority. Thread-safe via internal mutex.

§Ordering

Events are ordered by:

  1. Priority (lower value = higher precedence)
  2. Insertion order (earlier = higher precedence)

This ensures that high-priority events (like user input) are always processed before low-priority events (like render signals).

Implementations§

Source§

impl PriorityQueue

Source

pub fn new() -> Self

Create a new priority queue with default capacity.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a priority queue with specified capacity.

A capacity of 0 means unlimited (not recommended).

Source

pub fn push(&self, event: DynEvent) -> bool

Push an event onto the queue.

Returns false if capacity is exceeded (event is dropped).

Source

pub fn pop(&self) -> Option<DynEvent>

Pop the highest priority event.

Returns None if the queue is empty.

Source

pub fn peek_priority(&self) -> Option<u32>

Peek at the priority of the next event without removing it.

Returns None if the queue is empty.

Source

pub fn len(&self) -> usize

Get the number of events in the queue.

Source

pub fn is_empty(&self) -> bool

Check if the queue is empty.

Source

pub const fn capacity(&self) -> usize

Get the queue capacity.

Source

pub fn clear(&self)

Clear all events from the queue.

Source

pub fn drain(&self) -> Vec<DynEvent>

Drain all events from the queue in priority order.

Returns events sorted by priority (highest first).

Trait Implementations§

Source§

impl Debug for PriorityQueue

Source§

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

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

impl Default for PriorityQueue

Source§

fn default() -> Self

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

Auto Trait Implementations§

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.