Skip to main content

moirai_core/scheduler/
mod.rs

1//! Scheduler identity.
2//!
3//! The canonical work-stealing scheduler abstraction lives in `moirai-executor`
4//! as the [`WorkScheduler`] seam, implemented by `ThreadScheduler` and consumed
5//! by `HybridExecutor`. This module retains only [`SchedulerId`], the scheduler
6//! identifier used by metrics aggregation — the passive `Scheduler` trait,
7//! `ScheduledTask`, and the standalone deques/config that once lived here were
8//! dead duplicates of the executor's live types and have been removed.
9//!
10//! [`WorkScheduler`]: https://docs.rs/moirai-executor
11
12use core::fmt;
13
14/// A unique identifier for a scheduler instance.
15#[allow(clippy::module_name_repetitions)]
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
17pub struct SchedulerId(usize);
18
19impl SchedulerId {
20    /// Creates a new scheduler ID.
21    #[must_use]
22    pub const fn new(id: usize) -> Self {
23        Self(id)
24    }
25
26    /// Returns the raw ID value.
27    #[must_use]
28    pub const fn get(&self) -> usize {
29        self.0
30    }
31}
32
33impl fmt::Display for SchedulerId {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        write!(f, "Scheduler({})", self.0)
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use super::SchedulerId;
42
43    #[test]
44    fn scheduler_id_round_trips_and_displays() {
45        let id = SchedulerId::new(42);
46        assert_eq!(id.get(), 42);
47        assert_eq!(format!("{id}"), "Scheduler(42)");
48    }
49}