handler_map 0.1.0

Map from types to functions that receive them
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented1 out of 8 items with examples
  • Size
  • Source code size: 27 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.38 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • QuietMisdreavus/handler_map
    14 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • QuietMisdreavus

handler_map

like AnyMap, but with functions instead of values

This crate began with an idle thought: "Crates like AnyMap let you store one value of each type. What would it take to instead store a function that took that type, like a message handler?" What came out was this.

The basic idea is that you start with a message type, and a function that receives it by-value:

struct MyMessage;
fn handle_msg(_: MyMessage) {
    println!("Got your message!");
}

Then, take one of these HandlerMaps, and hand it the handler:

let mut map = HandlerMap::new();
map.insert(handle_msg);

This registers that type in the handler so you can call it later:

map.call(MyMessage);

// console prints "Got your message!"