1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use super::TypeInfo;
use crate::info::DedupedLabels;
use crate::scheduler::workload::Workload;
use crate::type_id::TypeId;
use crate::world::World;
use crate::{error, Label};
use alloc::boxed::Box;
use alloc::vec::Vec;
#[allow(clippy::type_complexity)]
pub struct WorkloadSystem {
#[doc(hidden)]
pub(crate) type_id: TypeId,
pub(crate) display_name: Box<dyn Label>,
pub(crate) system_fn: Box<dyn Fn(&World) -> Result<(), error::Run> + Send + Sync + 'static>,
pub(crate) borrow_constraints: Vec<TypeInfo>,
pub(crate) generator: Box<dyn Fn(&mut Vec<TypeInfo>) -> TypeId + Send + Sync + 'static>,
pub(crate) run_if:
Option<Box<dyn Fn(&World) -> Result<bool, error::Run> + Send + Sync + 'static>>,
pub(crate) tags: Vec<Box<dyn Label>>,
pub(crate) before_all: DedupedLabels,
pub(crate) after_all: DedupedLabels,
pub(crate) require_in_workload: DedupedLabels,
pub(crate) require_before: DedupedLabels,
pub(crate) require_after: DedupedLabels,
}
impl Extend<WorkloadSystem> for Workload {
fn extend<T: IntoIterator<Item = WorkloadSystem>>(&mut self, iter: T) {
self.systems.extend(iter.into_iter());
}
}
#[allow(clippy::type_complexity)]
pub struct RunIf {
pub(crate) system_fn: Box<dyn Fn(&World) -> Result<bool, error::Run> + Send + Sync + 'static>,
}
pub trait WorkloadRunIfFn: Send + Sync + 'static {
fn run(&self, world: &'_ World) -> Result<bool, error::Run>;
fn clone(&self) -> Box<dyn WorkloadRunIfFn>;
}
impl<F: Fn(&World) -> Result<bool, error::Run> + Clone + Send + Sync + 'static> WorkloadRunIfFn
for F
{
fn run(&self, world: &'_ World) -> Result<bool, error::Run> {
(self)(world)
}
fn clone(&self) -> Box<dyn WorkloadRunIfFn> {
Box::new(self.clone())
}
}
#[allow(clippy::type_complexity)]
pub(crate) trait ExtractWorkloadRunIf {
fn to_non_clone(
self,
) -> Box<dyn Fn(&World) -> Result<bool, error::Run> + Send + Sync + 'static>;
}
impl ExtractWorkloadRunIf for Box<dyn WorkloadRunIfFn> {
fn to_non_clone(
self,
) -> Box<dyn Fn(&World) -> Result<bool, error::Run> + Send + Sync + 'static> {
Box::new(move |world| self.run(world))
}
}
impl Clone for Box<dyn WorkloadRunIfFn> {
fn clone(&self) -> Box<dyn WorkloadRunIfFn> {
WorkloadRunIfFn::clone(&**self)
}
}