moirai_core/task/
traits.rs1use super::id_and_context::TaskContext;
2
3pub trait Task: Send + 'static {
5 type Output: Send + 'static;
7
8 fn execute(self) -> Self::Output;
10
11 fn context(&self) -> &TaskContext;
13
14 fn is_stealable(&self) -> bool {
16 true
17 }
18
19 fn estimated_cost(&self) -> u32 {
21 1
22 }
23}
24
25#[cfg(feature = "std")]
26impl<T> Task for Box<T>
27where
28 T: Task,
29{
30 type Output = T::Output;
31
32 fn execute(self) -> Self::Output {
33 (*self).execute()
34 }
35
36 fn context(&self) -> &TaskContext {
37 (**self).context()
38 }
39
40 fn is_stealable(&self) -> bool {
41 (**self).is_stealable()
42 }
43
44 fn estimated_cost(&self) -> u32 {
45 (**self).estimated_cost()
46 }
47}