llrt icon indicating copy to clipboard operation
llrt copied to clipboard

How to get the name of the module simply

Open ahaoboy opened this issue 1 year ago • 2 comments

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)

ahaoboy avatar Dec 21 '24 08:12 ahaoboy

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
  }
}

ahaoboy avatar Dec 21 '24 09:12 ahaoboy

We're working on improving this. The entire way modules are initialized/registered/provided will be changed soon.

richarddavison avatar Jan 23 '25 10:01 richarddavison