Struct shred::DispatcherBuilder
source · [−]pub struct DispatcherBuilder<'a, 'b> { /* private fields */ }
Expand description
Builder for the Dispatcher
.
Barriers
Barriers are a way of sequentializing parts of
the system execution. See add_barrier()
/with_barrier()
.
Examples
This is how you create a dispatcher with a shared thread pool:
let dispatcher: Dispatcher = DispatcherBuilder::new()
.with(system_a, "a", &[])
.with(system_b, "b", &["a"]) // b depends on a
.with(system_c, "c", &["a"]) // c also depends on a
.with(system_d, "d", &[])
.with(system_e, "e", &["c", "d"]) // e executes after c and d are finished
.build();
Systems can be conditionally added by using the add_
functions:
let mut builder = DispatcherBuilder::new()
.with(system_a, "a", &[]);
if b_enabled {
builder.add(system_b, "b", &[]);
}
let dispatcher = builder.build();
Implementations
sourceimpl<'a, 'b> DispatcherBuilder<'a, 'b>
impl<'a, 'b> DispatcherBuilder<'a, 'b>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new DispatcherBuilder
by using the Default
implementation.
The default behaviour is to create a thread pool on finish
.
If you already have a rayon ThreadPool
, it’s highly recommended to
configure this builder to use it with with_pool
instead.
sourcepub fn num_systems(&self) -> usize
pub fn num_systems(&self) -> usize
Returns the number of systems added to the builder
sourcepub fn has_system(&self, system: &str) -> bool
pub fn has_system(&self, system: &str) -> bool
Returns whether or not a specific system has been added to the builder
This is useful as add()
will throw if a dependency does not exist So you can use this
function to check if dependencies are satisfied
sourcepub fn with<T>(self, system: T, name: &str, dep: &[&str]) -> Self where
T: for<'c> System<'c> + Send + 'a,
pub fn with<T>(self, system: T, name: &str, dep: &[&str]) -> Self where
T: for<'c> System<'c> + Send + 'a,
Adds a new system with a given name and a list of dependencies. Please note that the dependency should be added before you add the depending system.
If you want to register systems which can not be specified as
dependencies, you can use ""
as their name, which will not panic
(using another name twice will).
Same as add()
, but
returns self
to enable method chaining.
Panics
- if the specified dependency does not exist
- if a system with the same name was already registered.
sourcepub fn add<T>(&mut self, system: T, name: &str, dep: &[&str]) where
T: for<'c> System<'c> + Send + 'a,
pub fn add<T>(&mut self, system: T, name: &str, dep: &[&str]) where
T: for<'c> System<'c> + Send + 'a,
Adds a new system with a given name and a list of dependencies. Please note that the dependency should be added before you add the depending system.
If you want to register systems which can not be specified as
dependencies, you can use ""
as their name, which will not panic
(using another name twice will).
Panics
- if the specified dependency does not exist
- if a system with the same name was already registered.
sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Returns true
if a system with the given name has been added to the
BispatcherBuilder
, otherwise, returns false.
sourcepub fn with_batch<T>(
self,
controller: T,
dispatcher_builder: DispatcherBuilder<'a, 'b>,
name: &str,
dep: &[&str]
) -> Self where
T: for<'c> BatchController<'a, 'b, 'c> + Send + 'a,
'b: 'a,
pub fn with_batch<T>(
self,
controller: T,
dispatcher_builder: DispatcherBuilder<'a, 'b>,
name: &str,
dep: &[&str]
) -> Self where
T: for<'c> BatchController<'a, 'b, 'c> + Send + 'a,
'b: 'a,
The Batch
is a System
which contains a Dispatcher
.
By wrapping a Dispatcher
inside a system, we can control the execution
of a whole group of system, without sacrificing parallelism or
conciseness.
This function accepts the DispatcherBuilder
as parameter, and the type
of the System
that will drive the execution of the internal
dispatcher.
Note that depending on the dependencies of the SubSystems the Batch can run in parallel with other Systems. In addition the Sub Systems can run in parallel within the Batch.
The Dispatcher
created for this Batch
is completelly separate,
from the parent Dispatcher
.
This mean that the dependencies, the System
names, etc.. specified on
the Batch
Dispatcher
are not visible on the parent, and is not
allowed to specify cross dependencies.
sourcepub fn add_batch<T>(
&mut self,
controller: T,
dispatcher_builder: DispatcherBuilder<'a, 'b>,
name: &str,
dep: &[&str]
) where
T: for<'c> BatchController<'a, 'b, 'c> + Send + 'a,
'b: 'a,
pub fn add_batch<T>(
&mut self,
controller: T,
dispatcher_builder: DispatcherBuilder<'a, 'b>,
name: &str,
dep: &[&str]
) where
T: for<'c> BatchController<'a, 'b, 'c> + Send + 'a,
'b: 'a,
The Batch
is a System
which contains a Dispatcher
.
By wrapping a Dispatcher
inside a system, we can control the execution
of a whole group of system, without sacrificing parallelism or
conciseness.
This function accepts the DispatcherBuilder
as parameter, and the type
of the System
that will drive the execution of the internal
dispatcher.
Note that depending on the dependencies of the SubSystems the Batch can run in parallel with other Systems. In addition the Sub Systems can run in parallel within the Batch.
The Dispatcher
created for this Batch
is completelly separate,
from the parent Dispatcher
.
This mean that the dependencies, the System
names, etc.. specified on
the Batch
Dispatcher
are not visible on the parent, and is not
allowed to specify cross dependencies.
sourcepub fn with_thread_local<T>(self, system: T) -> Self where
T: for<'c> RunNow<'c> + 'b,
pub fn with_thread_local<T>(self, system: T) -> Self where
T: for<'c> RunNow<'c> + 'b,
Adds a new thread local system.
Please only use this if your struct is not Send
and Sync
.
Thread-local systems are dispatched in-order.
Same as DispatcherBuilder::add_thread_local, but returns self
to
enable method chaining.
sourcepub fn add_thread_local<T>(&mut self, system: T) where
T: for<'c> RunNow<'c> + 'b,
pub fn add_thread_local<T>(&mut self, system: T) where
T: for<'c> RunNow<'c> + 'b,
Adds a new thread local system.
Please only use this if your struct is not Send
and Sync
.
Thread-local systems are dispatched in-order.
sourcepub fn with_barrier(self) -> Self
pub fn with_barrier(self) -> Self
Inserts a barrier which assures that all systems added before the barrier are executed before the ones after this barrier.
Does nothing if there were no systems added
since the last call to add_barrier()
/with_barrier()
.
Thread-local systems are not affected by barriers; they’re always executed at the end.
Same as DispatcherBuilder::add_barrier, but returns self
to enable
method chaining.
sourcepub fn add_barrier(&mut self)
pub fn add_barrier(&mut self)
Inserts a barrier which assures that all systems added before the barrier are executed before the ones after this barrier.
Does nothing if there were no systems added
since the last call to add_barrier()
/with_barrier()
.
Thread-local systems are not affected by barriers; they’re always executed at the end.
sourcepub fn with_pool(self, pool: Arc<ThreadPool>) -> Self
pub fn with_pool(self, pool: Arc<ThreadPool>) -> Self
Attach a rayon thread pool to the builder and use that instead of creating one.
Same as
add_pool()
,
but returns self
to enable method chaining.
sourcepub fn add_pool(&mut self, pool: Arc<ThreadPool>)
pub fn add_pool(&mut self, pool: Arc<ThreadPool>)
Attach a rayon thread pool to the builder and use that instead of creating one.
sourcepub fn print_par_seq(&self)
pub fn print_par_seq(&self)
Prints the equivalent system graph
that can be easily used to get the graph using the seq!
and par!
macros. This is only recommended for advanced users.
sourcepub fn build(self) -> Dispatcher<'a, 'b>
pub fn build(self) -> Dispatcher<'a, 'b>
Builds the Dispatcher
.
In the future, this method will precompute useful information in order to speed up dispatching.
sourceimpl<'b> DispatcherBuilder<'static, 'b>
impl<'b> DispatcherBuilder<'static, 'b>
sourcepub fn build_async<R>(self, world: R) -> AsyncDispatcher<'b, R>
pub fn build_async<R>(self, world: R) -> AsyncDispatcher<'b, R>
Builds an async dispatcher.
It does not allow non-static types and accepts a World
struct or a
value that can be borrowed as World
.
Trait Implementations
sourceimpl<'a, 'b> Debug for DispatcherBuilder<'a, 'b>
impl<'a, 'b> Debug for DispatcherBuilder<'a, 'b>
sourceimpl<'a, 'b> Default for DispatcherBuilder<'a, 'b>
impl<'a, 'b> Default for DispatcherBuilder<'a, 'b>
sourcefn default() -> DispatcherBuilder<'a, 'b>
fn default() -> DispatcherBuilder<'a, 'b>
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl<'a, 'b> !RefUnwindSafe for DispatcherBuilder<'a, 'b>
impl<'a, 'b> !Send for DispatcherBuilder<'a, 'b>
impl<'a, 'b> !Sync for DispatcherBuilder<'a, 'b>
impl<'a, 'b> Unpin for DispatcherBuilder<'a, 'b>
impl<'a, 'b> !UnwindSafe for DispatcherBuilder<'a, 'b>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more