moirai_executor/schedule/class/
mod.rs1mod sealed {
4 pub trait Sealed {}
5}
6
7pub trait WorkClass: sealed::Sealed + Send + Sync + 'static {
13 const AFFINITY_OFFSET: usize;
15
16 const SERIAL_AFFINITY_OFFSET: usize;
22
23 const NAME: &'static str;
25
26 const USES_ASYNC_LANE: bool;
28
29 const USES_BLOCKING_LANE: bool;
31}
32
33#[derive(Debug, Clone, Copy, Default)]
35pub struct SyncTask;
36
37#[derive(Debug, Clone, Copy, Default)]
39pub struct AsyncTask;
40
41#[derive(Debug, Clone, Copy, Default)]
43pub struct BlockingTask;
44
45impl sealed::Sealed for SyncTask {}
46impl sealed::Sealed for AsyncTask {}
47impl sealed::Sealed for BlockingTask {}
48
49impl WorkClass for SyncTask {
50 const AFFINITY_OFFSET: usize = 0;
51 const SERIAL_AFFINITY_OFFSET: usize = 0;
52 const NAME: &'static str = "sync";
53 const USES_ASYNC_LANE: bool = false;
54 const USES_BLOCKING_LANE: bool = false;
55}
56
57impl WorkClass for AsyncTask {
58 const AFFINITY_OFFSET: usize = 1;
59 const SERIAL_AFFINITY_OFFSET: usize = Self::AFFINITY_OFFSET;
60 const NAME: &'static str = "async";
61 const USES_ASYNC_LANE: bool = true;
62 const USES_BLOCKING_LANE: bool = false;
63}
64
65impl WorkClass for BlockingTask {
66 const AFFINITY_OFFSET: usize = 2;
67 const SERIAL_AFFINITY_OFFSET: usize = Self::AFFINITY_OFFSET;
68 const NAME: &'static str = "blocking";
69 const USES_ASYNC_LANE: bool = false;
70 const USES_BLOCKING_LANE: bool = true;
71}
72
73#[cfg(test)]
74mod tests {
75 use super::{AsyncTask, BlockingTask, SyncTask};
76
77 #[test]
78 fn work_class_markers_are_zero_sized() {
79 assert_eq!(core::mem::size_of::<SyncTask>(), 0);
80 assert_eq!(core::mem::size_of::<AsyncTask>(), 0);
81 assert_eq!(core::mem::size_of::<BlockingTask>(), 0);
82 }
83}