#resources #ecs #parallel #systems #access-control #system #derive-debug

shred

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

43 releases

0.16.0 Jan 12, 2024
0.15.0 Sep 16, 2023
0.14.1 Jul 14, 2022
0.12.0 Jun 7, 2021
0.4.3 Jun 21, 2017

#8 in #ecs

Download history 2514/week @ 2024-01-18 1872/week @ 2024-01-25 1541/week @ 2024-02-01 2519/week @ 2024-02-08 2839/week @ 2024-02-15 2315/week @ 2024-02-22 2345/week @ 2024-02-29 3031/week @ 2024-03-07 2186/week @ 2024-03-14 2844/week @ 2024-03-21 2847/week @ 2024-03-28 2790/week @ 2024-04-04 2873/week @ 2024-04-11 2824/week @ 2024-04-18 2759/week @ 2024-04-25 2629/week @ 2024-05-02

11,175 downloads per month
Used in 120 crates (13 directly)

MIT/Apache

160KB
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.56.1 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

~3.5MB
~73K SLoC