I'm looking for the right method to statically register structures at compile time.
The origin of this requirement is to have a bunch of applets with dedicated tasks so that if I run myprog foo, it will call the foo applet.
So I started by defining an Applet structure:
struct Applet {
name: &str,
call: fn(),
}
Then I can define my foo applet this way:
fn foo_call() {
println!("Foo");
}
let foo_applet = Applet { name: "foo", call: foo_call };
Now I would like to register this applet so that my main function can call it if available:
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
match AppletRegistry.get(args[1]) {
Some(x) => x.call(),
_ => (),
}
}
The whole deal is about how AppletRegistry should be implemented so that I can list all the available applets preferably at compile time.