15 releases

0.7.0 Jan 12, 2024
0.6.3 Dec 21, 2020
0.6.2 Feb 11, 2020
0.6.1 Jun 23, 2019
0.3.0 Jun 5, 2017

#221 in #systems

Download history 1267/week @ 2023-12-23 822/week @ 2023-12-30 1675/week @ 2024-01-06 1964/week @ 2024-01-13 1721/week @ 2024-01-20 1450/week @ 2024-01-27 1300/week @ 2024-02-03 1904/week @ 2024-02-10 2076/week @ 2024-02-17 1515/week @ 2024-02-24 1703/week @ 2024-03-02 1880/week @ 2024-03-09 1738/week @ 2024-03-16 1900/week @ 2024-03-23 1992/week @ 2024-03-30 1197/week @ 2024-04-06

6,914 downloads per month
Used in 97 crates (7 directly)

MIT/Apache

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

~1.5MB
~33K SLoC