des_sim/modeling/event.rs
1//! The `event` module defines the core components for representing events in the simulation.
2//!
3//! It includes `EventPriority` for ordering events and the `Event` struct itself,
4//! which encapsulates a unique ID, priority, and a generic payload for application-specific data.
5
6use crate::primitive::id::EventId;
7
8/// Represents the priority of an event.
9/// Higher numerical values indicate higher priority.
10#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
11pub struct EventPriority(u8);
12
13impl Default for EventPriority {
14 fn default() -> Self {
15 EventPriority::minimum()
16 }
17}
18
19impl EventPriority {
20 /// Creates a new `EventPriority` with the specified value.
21 pub const fn new(v: u8) -> EventPriority {
22 EventPriority(v)
23 }
24
25 /// Returns the lowest possible event priority.
26 pub const fn minimum() -> EventPriority {
27 EventPriority(u8::MIN)
28 }
29
30 /// Returns the highest possible event priority.
31 pub const fn maximum() -> EventPriority {
32 EventPriority(u8::MAX)
33 }
34
35 /// Returns the raw numerical value of the priority.
36 pub const fn value(&self) -> u8 {
37 self.0
38 }
39}
40
41/// Represents a scheduled event within the simulation.
42#[derive(Clone, Debug)]
43pub struct Event<E> {
44 /// Unique identifier for the event.
45 pub event_id: EventId,
46 /// Priority level that determines the execution order for events at the same simulation time.
47 pub priority: EventPriority,
48 /// The application-specific data payload associated with this event.
49 pub payload: E,
50}
51
52impl<E> Event<E> {
53 /// Creates a new `Event` instance.
54 pub(crate) fn new(event_id: EventId, priority: EventPriority, payload: E) -> Self {
55 Self {
56 event_id,
57 priority,
58 payload,
59 }
60 }
61}