Crate shred [] [src]

Shared resource dispatcher

This library allows to dispatch systems, which can have interdependencies, shared and exclusive resource access, in parallel.

Examples

extern crate shred;
#[macro_use]
extern crate shred_derive;

use shred::{DispatcherBuilder, Fetch, FetchMut, Resource, Resources, System};

#[derive(Debug)]
struct ResA;

#[derive(Debug)]
struct ResB;

#[derive(SystemData)]
struct Data<'a> {
    a: Fetch<'a, ResA>,
    b: FetchMut<'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);
    }
}


fn main() {
    let mut resources = Resources::new();
    let mut dispatcher = DispatcherBuilder::new()
        .with(EmptySystem, "empty", &[])
        .build();
    resources.add(ResA);
    resources.add(ResB);

    dispatcher.dispatch(&mut resources);
}

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.

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

AsyncDispatcher

Like, Dispatcher but works asynchronously.

Dispatcher

The dispatcher struct, allowing systems to be executed in parallel.

DispatcherBuilder

Builder for the Dispatcher.

Fetch

Return value of Resources::fetch.

FetchId

Return value of Resources::fetch_id.

FetchIdMut

Return value of Resources::fetch_id_mut.

FetchMut

Return value of Resources::fetch_mut.

Par

Runs two tasks in parallel. These two tasks are called head and tail in the following documentation.

ParSeq

A dispatcher intended to be used with Par and Seq structures.

ResourceId

The id of a Resource, which is a tuple struct with a type id and an additional resource id (represented with a usize).

Resources

A resource container, which provides methods to access to the contained resources.

Seq

Runs two tasks sequentially. These two tasks are called head and tail in the following documentation.

Enums

RunningTime

Traits

Resource

A resource defines a set of data which can 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.

System

A System, executed with a set of required Resources.

SystemData

A struct implementing system data indicates that it bundles some resources which are required for the execution.