Skip to content
Shared resource dispatcher
Branch: master
Clone or download
3 authors Merge #105
105: Update HashMaps to use hashbrown HashMap r=torkleyy a=bdelmas

A small update of the `FxHashMap` `HashMap` to use the more perfomante `hashbrown` `HashMap`.

[`hashbrown`](https://github.com/Amanieu/hashbrown) is a Rust port of Google's high-performance SwissTable hash map and is around [2 times faster](https://github.com/Amanieu/hashbrown#features) than `FxHashMap`.

Co-authored-by: Benjamin Delmas <bdelmas.pro@gmail.com>
Co-authored-by: Jacob Kiesel <xaeroxe@amethyst-engine.org>
Latest commit 8474fe2 Jan 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benches Renamed 'Resource' to 'World' Jan 17, 2019
examples
shred-derive Renamed 'Resource' to 'World' Jan 17, 2019
src
tests Renamed 'Resource' to 'World' Jan 17, 2019
.gitignore Initial commit Apr 29, 2017
.travis.yml
Cargo.toml
LICENSE-APACHE
LICENSE-MIT Improve README, add license May 6, 2017
README.md
bors.toml Add bors.toml Jun 3, 2017
rustfmt.toml

README.md

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, World, System, 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 resources = World::new();
    let mut dispatcher = DispatcherBuilder::new()
        .with(PrintSystem, "print", &[]) // Adds a system "print" without dependencies
        .build();
    //resources.add(ResA); (We don't need to add `ResA`, a default value will be instantiated)
    resources.insert(ResB);

    dispatcher.dispatch(&mut resources);
}

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

Required Rust version

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

You can’t perform that action at this time.