#[derive(Task)]
{
// Attributes available to this derive:
#[title]
}
Expand description
Implementation for a Task to run with the scheduler
The derive will generate a new method to create a task,
and wrap each fields inside TaskState<T>.
The title attribute, allow the user to choose a unique title.
§Example
ⓘ
#[derive(Task)]
#[title(format = "Task {self.id} {self.name}")]
struct Task {
id: TaskState<u32>,
name: TaskState<String>,
...
}
struct SecondTask {
id: TaskState<u32>,
...
}In this example, the task implementation will look like this:
ⓘ
impl Task {
pub fn new(id: u32, name: String) -> Self {
Self {
id: TaskState::new(id),
name: TaskState::new(name),
}
}
}
impl UniqueId for Task {}
impl Task for Task {
fn title(&self) -> String {
format!("Task {} {}", &*self.id.read().unwrap(), &*self.name.read().unwrap())
}
}
impl SecondTask {
pub fn new(id: u32) -> Self {
Self {
id: TaskState::new(id),
}
}
}
impl UniqueId for SecondTask {}
impl Task for SecondTask {}