Crates.io | dispatchtable |
lib.rs | dispatchtable |
version | 0.2.0 |
source | src |
created_at | 2020-03-10 08:47:38.109066 |
updated_at | 2020-03-13 21:14:01.806944 |
description | Small library used to specify function dispatch tables HashMap |
homepage | https://github.com/Skarlett/dispatchtable |
repository | https://github.com/Skarlett/dispatchtable |
max_upload_size | |
id | 217189 |
size | 8,842 |
A rust library used for storing functions inside a key-based collection.
use dispatchtable::{DispatchTable, Dispatch};
fn add(params: &(isize, isize)) -> isize {
params.0 + params.1
}
fn sub(params: &(isize, isize)) -> isize {
params.0 + params.1
}
fn main() {
let mut table = DispatchTable::new();
table.insert("add", Box::new(add));
table.insert("sub", Box::new(sub));
assert_eq!(table.call(&"add", &(1, 2)), Some(3));
assert_eq!(table.call(&"sub", &(5, 2)), Some(3));
}