#parallel #systems #resources #ecs

shred

Dispatches systems in parallel which need read access to some resources, and write access to others

35 releases

✓ Uses Rust 2018 edition

0.10.2 Feb 12, 2020
0.10.0 Dec 31, 2019
0.9.4 Nov 15, 2019
0.9.2 Jun 28, 2019
0.4.3 Jun 21, 2017

#6 in Concurrency

Download history 1191/week @ 2019-11-08 3226/week @ 2019-11-15 1699/week @ 2019-11-22 1069/week @ 2019-11-29 1079/week @ 2019-12-06 966/week @ 2019-12-13 1185/week @ 2019-12-20 1753/week @ 2019-12-27 1537/week @ 2020-01-03 1723/week @ 2020-01-10 1895/week @ 2020-01-17 1373/week @ 2020-01-24 1335/week @ 2020-01-31 1463/week @ 2020-02-07 1664/week @ 2020-02-14

6,672 downloads per month
Used in 125 crates (14 directly)

MIT/Apache

155KB
3K SLoC

shred - Shared resource dispatcher

Build Status Crates.io MIT/Apache Docs.rs LoC

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

Usage

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);
    }
}

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

    dispatcher.dispatch(&mut world);
}

Please see the benchmark for a bigger (and useful) example.

Required Rust version

1.38 stable

Features

  • lock-free
  • no channels or similar functionality used (-> less overhead)
  • allows both automated parallelization and fine-grained control

Contribution

Contribution is highly welcome! If you'd like another feature, just create an issue. You can also help out if you want to; just pick a "help wanted" issue. If you need any help, feel free to ask!

All contributions are assumed to be dual-licensed under MIT/Apache-2.

License

shred is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT.

Dependencies

~1.7–2.3MB
~47K SLoC