Crate shred [] [src]

Shared resource dispatcher

This library allows to dispatch tasks, 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, Task};

#[derive(Debug)]
struct ResA;

impl Resource for ResA {}

#[derive(Debug)]
struct ResB;

impl Resource for ResB {}

#[derive(TaskData)]
struct Data<'a> {
    a: Fetch<'a, ResA>,
    b: FetchMut<'a, ResB>,
}

struct EmptyTask;

impl<'a> Task<'a> for EmptyTask {
    type TaskData = Data<'a>;

    fn work(&mut self, bundle: Data<'a>) {
        println!("{:?}", &*bundle.a);
        println!("{:?}", &*bundle.b);
    }
}


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

    dispatcher.dispatch(&mut resources);
}

Structs

Dispatcher

The dispatcher struct, allowing tasks 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.

Resources

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

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).

Task

A Task, executed with a set of required Resources.

TaskData

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

Type Definitions

ResourceId

The id of a Resource, which is the same as it's type id at the moment.