Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the name of the module simply #751

Open
ahaoboy opened this issue Dec 21, 2024 · 2 comments
Open

How to get the name of the module simply #751

ahaoboy opened this issue Dec 21, 2024 · 2 comments

Comments

@ahaoboy
Copy link
Contributor

ahaoboy commented Dec 21, 2024

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
Copy link
Contributor Author

ahaoboy commented Dec 21, 2024

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

@richarddavison
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@ahaoboy @richarddavison and others