#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TaskId(pub u64);
impl core::fmt::Display for TaskId {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Task#{}", self.0)
}
}
impl TaskId {
pub const fn new(id: u64) -> Self {
Self(id)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub enum Priority {
Low = 0,
#[default]
Normal = 1,
High = 2,
Critical = 3,
}
impl Priority {
#[must_use]
pub const fn index(self) -> usize {
self as usize
}
}
#[derive(Debug, Clone)]
pub struct TaskContext {
pub id: TaskId,
pub priority: Priority,
pub name: Option<&'static str>,
}
impl TaskContext {
pub const fn new(id: TaskId) -> Self {
Self {
id,
priority: Priority::Normal,
name: None,
}
}
pub const fn with_priority(mut self, priority: Priority) -> Self {
self.priority = priority;
self
}
pub const fn with_name(mut self, name: &'static str) -> Self {
self.name = Some(name);
self
}
}