llrt
llrt copied to clipboard
How to get the name of the module simply
The module name can be obtained through ModuleInfo, but it requires a relatively long code. Is it possible to implement a name function for the module?
.with_module("path", PathModule)
.with_module(Into::<ModuleInfo<PathModule>>::into(PathModule).name, PathModule)
.with_module(PathModule::name(), PathModule)
One possible way is to automatically implement a trait
pub trait ModuleName {
fn name(self) -> &'static str;
}
impl<T> ModuleName for T
where
T: ModuleDef,
ModuleInfo<T>: From<T>,
{
fn name(self) -> &'static str {
Into::<ModuleInfo<T>>::into(self).name
}
}
We're working on improving this. The entire way modules are initialized/registered/provided will be changed soon.