mod_events/
priority.rs

1//! Priority system for event listeners
2
3/// Priority levels for event listeners
4///
5/// Listeners with higher priority are executed first.
6/// This allows for controlling the execution order of event handlers.
7///
8/// # Example
9///
10/// ```rust
11/// use mod_events::{EventDispatcher, Priority, Event};
12///
13/// #[derive(Debug, Clone)]
14/// struct MyEvent {
15///     message: String,
16/// }
17///
18/// impl Event for MyEvent {
19///     fn as_any(&self) -> &dyn std::any::Any {
20///         self
21///     }
22/// }
23///
24/// let dispatcher = EventDispatcher::new();
25///
26/// // This will execute first
27/// dispatcher.subscribe_with_priority(|event: &MyEvent| {
28///     println!("High priority handler");
29///     Ok(())
30/// }, Priority::High);
31///
32/// // This will execute second
33/// dispatcher.subscribe_with_priority(|event: &MyEvent| {
34///     println!("Normal priority handler");
35///     Ok(())
36/// }, Priority::Normal);
37/// ```
38#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
39pub enum Priority {
40    /// Lowest priority (0)
41    Lowest = 0,
42    /// Low priority (25)
43    Low = 25,
44    /// Normal priority (50) - default
45    #[default]
46    Normal = 50,
47    /// High priority (75)
48    High = 75,
49    /// Highest priority (100)
50    Highest = 100,
51    /// Critical priority (125) - use sparingly
52    Critical = 125,
53}
54
55impl Priority {
56    /// Get all priority levels in order
57    pub fn all() -> &'static [Priority] {
58        &[
59            Priority::Critical,
60            Priority::Highest,
61            Priority::High,
62            Priority::Normal,
63            Priority::Low,
64            Priority::Lowest,
65        ]
66    }
67}