#parallel #systems #resources #ecs #derive

macro shred-derive

Custom derive for shred

13 releases

0.6.2 Feb 11, 2020
0.6.1 Jun 23, 2019
0.6.0 Apr 18, 2019
0.5.1 Oct 28, 2018
0.3.0 Jun 5, 2017

#95 in Concurrency

Download history 595/week @ 2019-12-02 648/week @ 2019-12-09 700/week @ 2019-12-16 947/week @ 2019-12-23 1191/week @ 2019-12-30 1244/week @ 2020-01-06 1161/week @ 2020-01-13 784/week @ 2020-01-20 910/week @ 2020-01-27 1028/week @ 2020-02-03 1126/week @ 2020-02-10 1174/week @ 2020-02-17 1031/week @ 2020-02-24 739/week @ 2020-03-02 1062/week @ 2020-03-09 1670/week @ 2020-03-16

4,387 downloads per month
Used in 117 crates (7 directly)

MIT/Apache

6KB
114 lines

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

~450–760KB
~18K SLoC