dispatchtable

Crates.iodispatchtable
lib.rsdispatchtable
version0.2.0
sourcesrc
created_at2020-03-10 08:47:38.109066
updated_at2020-03-13 21:14:01.806944
descriptionSmall library used to specify function dispatch tables HashMap>
homepagehttps://github.com/Skarlett/dispatchtable
repositoryhttps://github.com/Skarlett/dispatchtable
max_upload_size
id217189
size8,842
Lunarix (Skarlett)

documentation

README

DispatchTable

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));
}
Commit count: 16

cargo fmt