#specs #messenger #component

specs_messenger

message passing component for specs

1 unstable release

Uses old Rust 2015

0.1.0 Jun 24, 2018

#12 in #messenger

MIT license

8KB
172 lines

specs_messenger

message passing component for specs

let mut world = World::new();

let mut dispatcher = SpecsBundler::new(&mut world, DispatcherBuilder::new())
    .bundle(MessengerBundle::<String>::new()).unwrap()
    .build();

let entity0 = world
    .create_entity()
    .with(Messenger::<String>::new())
    .build();

let entity1 = world
    .create_entity()
    .with(Messenger::<String>::new())
    .build();

let entity2 = world
    .create_entity()
    .with(Messenger::<String>::new())
    .build();

{
    let mut messengers = world.write_storage::<Messenger<String>>();

    messengers
        .get_mut(entity0)
        .unwrap()
        .send(entity1, "Direct".into());

    messengers
        .get_mut(entity2)
        .unwrap()
        .broadcast("Broadcast".into());
}

dispatcher.dispatch(&mut world.res);

Dependencies

~6MB
~119K SLoC