No description
Find a file
bors[bot] b40c431f53 Merge #150
150: Change wording in BatchController and impose Send requirements r=torkleyy a=WaDelma

Because panicking is general not unsafe, changes the doc comment of `BatchController::create` to better match the doc comment of the trait regarding safety.

As the implementers of the trait are supposed to be `Send` I added the requirement explicitly. 

I am still not sure why `Dispatcher` isn't `Send`, so I am not sure about the safety considerations.

Co-authored-by: Delma <delma@del.ma>
2019-08-04 14:43:09 +00:00
benches Add benchmarks to show benefit on direct refs 2019-05-23 22:43:33 +02:00
examples Update examples/batch_dispatching.rs 2019-07-14 14:30:20 +02:00
shred-derive Formatting 2019-06-23 18:23:09 +02:00
src Removed the Send bound and fixed typo 2019-08-03 08:52:12 +03:00
tests Add dyn to all trait objects 2019-06-28 09:38:53 +02:00
.gitignore Initial commit 2017-04-29 18:20:58 +02:00
.travis.yml Add "shred-derive" feature to travis script 2019-06-28 10:46:05 +02:00
bors.toml Add bors.toml 2017-06-03 09:19:32 +02:00
Cargo.toml Added missing new line on the Cargo.toml file 2019-08-02 07:41:41 +02:00
LICENSE-APACHE Improve README, add license 2017-05-06 11:40:07 +02:00
LICENSE-MIT Improve README, add license 2017-05-06 11:40:07 +02:00
README.md Improve README 2019-03-29 11:16:14 +01:00
rustfmt.toml Format crate 2019-06-28 09:39:38 +02:00

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, System, World, Write};

#[derive(Debug, Default)]
struct ResA;

#[derive(Debug, Default)]
struct ResB;

struct PrintSystem;

// Systems should be generic over the
// context if possible, so it's easy
// to introduce one.
impl<'a> System<'a> for PrintSystem {
    type SystemData = (Read<'a, ResA>, Write<'a, ResB>);

    fn run(&mut self, data: Self::SystemData) {
        let (a, mut b) = data;

        println!("{:?}", &*a);
        println!("{:?}", &*b);

        *b = ResB; // We can mutate ResB here
        // because it's `FetchMut`.
    }
}

fn main() {
    let mut world = World::new();
    let mut dispatcher = DispatcherBuilder::new()
        .with(PrintSystem, "print", &[]) // Adds a system "print" without dependencies
        .build();
    //world.add(ResA); (We don't need to add `ResA`, a default value will be instantiated)
    world.insert(ResB);

    dispatcher.dispatch(&mut world);
}

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

Required Rust version

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