Hi all.
I want to develop a plugin system within my program, and I have a trait that functions defined by plugins should implement.
Currently, my code gets all the functions in a HashMap and then calls them by their name. Problem is, I have to create that hashmap myself by inserting every function myself.
I would really appreciate it if there was a way to say, suppose, all pub members of mod functions::
that implement this trait PluginFunction
call register(hashmap)
function. So as I add more functions as mod
in functions
it'll be automatically added on compile.
Pseudocode:
Files:
src/
├── attrs.rs
├── functions
│ ├── attrs.rs
│ ├── export.rs
│ └── render.rs
├── functions.rs
├── lib.rs
Basically, in mod functions
I want:
impl AllFunctions{
pub fn new() -> Self {
let mut functions_map = HashMap::new();[[
register_all!(crate::functions::* implementing PluginFunction, &mut functions_map);
Self { function_map }
}
}
Right now I'm doing:
impl AllFunctions{
pub fn new() -> Self {
let mut functions_map = HashMap::new();[[
crate::functions::attrs::PrintAttr{}.register(&mut functions_map);
crate::functions::export::ExportCSV{}.register(&mut functions_map);
crate::functions::render::RenderText{}.register(&mut functions_map);
// More as I add more functions
Self { function_map }
}
}
I'll repeat it as much as I can but we need yo open up new journals for these kind of things.
All we need is a good cloud for storage, and volunteers. I think comp-sci people do that with https://arxiv.org/
The journal should accept any user submitted papers but have ranking based on other people, like successful reproducible studies (which is also accepted in journal) will be linked to the original journal. Reviews and such can be their own articles but also linked to the journal.
That way, undergrads can do projects reproducing previous studies (given resources) which will still give them research credit. Failures and exploration will also give people credit as it helps other people's research. We can just tag papers for novel ideas,failures, reproducing old paper,reviews, etc.
I think it has a chance to be very useful if we can pull it off. Although it'll have the same problems as of social media with upvote system. So some more thoughts needs to be there for the actual implementation.