mod sealed {
pub trait Sealed {}
}
pub trait WorkClass: sealed::Sealed + Send + Sync + 'static {
const AFFINITY_OFFSET: usize;
const SERIAL_AFFINITY_OFFSET: usize;
const NAME: &'static str;
const USES_ASYNC_LANE: bool;
const USES_BLOCKING_LANE: bool;
}
#[derive(Debug, Clone, Copy, Default)]
pub struct SyncTask;
#[derive(Debug, Clone, Copy, Default)]
pub struct AsyncTask;
#[derive(Debug, Clone, Copy, Default)]
pub struct BlockingTask;
impl sealed::Sealed for SyncTask {}
impl sealed::Sealed for AsyncTask {}
impl sealed::Sealed for BlockingTask {}
impl WorkClass for SyncTask {
const AFFINITY_OFFSET: usize = 0;
const SERIAL_AFFINITY_OFFSET: usize = 0;
const NAME: &'static str = "sync";
const USES_ASYNC_LANE: bool = false;
const USES_BLOCKING_LANE: bool = false;
}
impl WorkClass for AsyncTask {
const AFFINITY_OFFSET: usize = 1;
const SERIAL_AFFINITY_OFFSET: usize = Self::AFFINITY_OFFSET;
const NAME: &'static str = "async";
const USES_ASYNC_LANE: bool = true;
const USES_BLOCKING_LANE: bool = false;
}
impl WorkClass for BlockingTask {
const AFFINITY_OFFSET: usize = 2;
const SERIAL_AFFINITY_OFFSET: usize = Self::AFFINITY_OFFSET;
const NAME: &'static str = "blocking";
const USES_ASYNC_LANE: bool = false;
const USES_BLOCKING_LANE: bool = true;
}
#[cfg(test)]
mod tests {
use super::{AsyncTask, BlockingTask, SyncTask};
#[test]
fn work_class_markers_are_zero_sized() {
assert_eq!(core::mem::size_of::<SyncTask>(), 0);
assert_eq!(core::mem::size_of::<AsyncTask>(), 0);
assert_eq!(core::mem::size_of::<BlockingTask>(), 0);
}
}