| Crates.io | doko |
| lib.rs | doko |
| version | 0.1.1 |
| created_at | 2024-11-30 20:40:07.258663+00 |
| updated_at | 2024-12-04 07:28:47.21743+00 |
| description | Run methods from submodules by name |
| homepage | |
| repository | https://github.com/nonolai/doko |
| max_upload_size | |
| id | 1466969 |
| size | 19,355 |
dokoRun methods in submodules by name
doko lets you include and run a method from a known submodule without importing and creating the
map from name to method yourself. Behind the scenes, the doko::doko! macro:
moddoko_<function> that takes a module name and returns
<module name>::<function>. You can then call this function with whatever arguments you need.Created to improve project layout for things like Project Euler and Advent of Code.
project/
└──── src/
├──── main.rs
└──── submod/
├───── a.rs
└───── b.rs
project/src/submod/a.rspub fn greeting(name: &str) -> u32 {
println!("Hello, {}, from a", name);
4
}
project/src/submod/b.rspub fn greeting(name: &str) -> u32 {
println!("Hello, {}, from b", name);
5
}
project/src/main.rsdoko::doko!("src/submod", "greeting", (&str) -> u32);
pub fn main() {
let name = "username";
assert_eq!(4, doko_greeting("a")(name));
assert_eq!(5, doko_greeting("b")(name));
}
let registry = doko::doko!(...); registry.run(<module>);)