bevy_ecs/schedule/graph/
node.rs

1use core::fmt::Debug;
2
3/// Unique identifier for a system or system set stored in a [`ScheduleGraph`].
4///
5/// [`ScheduleGraph`]: crate::schedule::ScheduleGraph
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
7pub enum NodeId {
8    /// Identifier for a system.
9    System(usize),
10    /// Identifier for a system set.
11    Set(usize),
12}
13
14impl NodeId {
15    /// Returns the internal integer value.
16    pub const fn index(&self) -> usize {
17        match self {
18            NodeId::System(index) | NodeId::Set(index) => *index,
19        }
20    }
21
22    /// Returns `true` if the identified node is a system.
23    pub const fn is_system(&self) -> bool {
24        matches!(self, NodeId::System(_))
25    }
26
27    /// Returns `true` if the identified node is a system set.
28    pub const fn is_set(&self) -> bool {
29        matches!(self, NodeId::Set(_))
30    }
31
32    /// Compare this [`NodeId`] with another.
33    pub const fn cmp(&self, other: &Self) -> core::cmp::Ordering {
34        use core::cmp::Ordering::{Equal, Greater, Less};
35        use NodeId::{Set, System};
36
37        match (self, other) {
38            (System(a), System(b)) | (Set(a), Set(b)) => match a.checked_sub(*b) {
39                None => Less,
40                Some(0) => Equal,
41                Some(_) => Greater,
42            },
43            (System(_), Set(_)) => Less,
44            (Set(_), System(_)) => Greater,
45        }
46    }
47}