Expand description
Shared resource dispatcher
This library allows to dispatch systems, which can have interdependencies, shared and exclusive resource access, in parallel.
§Examples
extern crate shred;
use shred::{DispatcherBuilder, Read, Resource, ResourceId, System, SystemData, World, Write};
#[derive(Debug, Default)]
struct ResA;
#[derive(Debug, Default)]
struct ResB;
#[derive(SystemData)] // Provided with `shred-derive` feature
struct Data<'a> {
a: Read<'a, ResA>,
b: Write<'a, ResB>,
}
struct EmptySystem;
impl<'a> System<'a> for EmptySystem {
type SystemData = Data<'a>;
fn run(&mut self, bundle: Data<'a>) {
println!("{:?}", &*bundle.a);
println!("{:?}", &*bundle.b);
}
}
let mut world = World::empty();
let mut dispatcher = DispatcherBuilder::new()
.with(EmptySystem, "empty", &[])
.build();
world.insert(ResA);
world.insert(ResB);
dispatcher.dispatch(&mut world);Once you are more familiar with how system data and parallelization works,
you can take look at a more flexible and performant way to dispatch:
ParSeq. Using it is bit trickier, but it allows dispatching without any
virtual function calls.
Modules§
- cell
- Re-exports from
atomic_refcell
Macros§
- par
- The
par!macro may be used to easily create a structure which runs things in parallel. - seq
- The
seq!macro may be used to easily create a structure which runs things sequentially.
Structs§
- Async
Dispatcher - Like,
Dispatcherbut works asynchronously. - Batch
Accessor - The
BatchAccessoris used to notify the main dispatcher of the read and write resources of theSystems contained in the batch (“sub systems”). - Batch
Unchecked World - The
BatchUncheckedWorldwraps an instance of the world. You have to specify this asSystemDatafor aSystemimplementingBatchController. - Default
Provider - A
SetupHandlerthat simply uses the default implementation. - Dispatcher
- The dispatcher struct, allowing systems to be executed in parallel.
- Dispatcher
Builder - Builder for the
Dispatcher. - Entry
- An entry to a resource of the
Worldstruct. This is similar to the Entry API found in the standard library. - Fetch
- Allows to fetch a resource in a system immutably.
- Fetch
Mut - Allows to fetch a resource in a system mutably.
- Meta
Iter - An iterator for the
MetaTable. - Meta
Iter Mut - A mutable iterator for the
MetaTable. - Meta
Table - The
MetaTablewhich allows to store object-safe trait implementations for resources. - Multi
Dispatcher - A bridge from
MultiDispatchControllertoBatchController. - Panic
Handler - A setup handler that simply does nothing and thus will cause a panic on fetching.
- Par
- Runs two tasks in parallel.
These two tasks are called
headandtailin the following documentation. - ParSeq
- A dispatcher intended to be used with
ParandSeqstructures. - Read
- Allows to fetch a resource in a system immutably.
- Resource
Id - The id of a
Resource, which simply wraps a type id and a “dynamic ID”. The “dynamic ID” is usually just left0, and, unless such documentation says otherwise, other libraries will assume that it is always0; non-zero IDs are only used for special resource types that are specifically defined in a more dynamic way, such that resource types can essentially be created at run time, without having different static types. - Send
Dispatcher Sendable version ofDispatcher.- Seq
- Runs two tasks sequentially.
These two tasks are called
headandtailin the following documentation. - Static
Accessor - The static accessor that is used for
SystemData. - World
- A Resource container, which provides methods to insert, access and manage the contained resources.
- Write
- Allows to fetch a resource in a system mutably.
Enums§
- Accessor
Cow - Either an
Accessorof the systemTor a reference to it. - Running
Time
Traits§
- Accessor
- A trait for accessing read/write multiple resources from a system. This can be used to create dynamic systems that don’t specify what they fetch at compile-time.
- Batch
Controller - The
BatchControllerdescribes things that allow one to control how batches of systems are executed. - Cast
From - Helper trait for the
MetaTable. - Dynamic
System Data - A struct implementing system data indicates that it bundles some resources which are required for the execution.
- Multi
Dispatch Controller - The controlling parts of simplified
BatchControllers for running a batch fixed number of times. - Resource
- A resource is a data slot which lives in the
Worldcan only be accessed according to Rust’s typical borrowing model (one writer xor multiple readers). - RunNow
- Trait for fetching data and running systems. Automatically implemented for systems.
- RunWith
Pool - Similar to
RunNowexcept additionally taking in a rayon::ThreadPool for parallelism. - Setup
Handler - A setup handler performing the fetching of
T. - System
- A
System, executed with a set of requiredResources. - System
Data - A static system data that can specify its dependencies at statically (at
compile-time). Most system data is a
SystemData, theDynamicSystemDatatype is only needed for very special setups.
Type Aliases§
- Read
Expect - Allows to fetch a resource in a system immutably.
This will panic if the resource does not exist.
Usage of
ReadorOption<Read>is therefore recommended. - Resources
Deprecated - Alias for
Worldfor easier migration to the new version. Will be removed in the future. - Write
Expect - Allows to fetch a resource in a system mutably.
This will panic if the resource does not exist.
Usage of
WriteorOption<Write>is therefore recommended.
Derive Macros§
- System
Data - A reexport of the
#[derive(SystemData]macro provided byshred-derive. This requires that theshred-derivefeature is enabled. Used to#[derive]the traitSystemData.