module_registry/macros.rs
1//! Macros for module registry
2
3/// Macro for registering modules with inventory
4///
5/// # Example
6///
7/// ```ignore
8/// use module_registry::register_module;
9///
10/// register_module!("my_module", "MyModule", create_my_module);
11/// ```
12#[macro_export]
13macro_rules! register_module {
14 ($name:expr, $struct_name:expr, $factory:path) => {
15 inventory::submit! {
16 $crate::ModuleRegistration {
17 name: $name,
18 module_type: "module",
19 instantiate_fn_name: stringify!($factory),
20 module_path: module_path!(),
21 struct_name: $struct_name,
22 factory: $factory,
23 }
24 }
25 };
26}
27
28/// Macro to get the current module path
29#[macro_export]
30macro_rules! module_path {
31 () => {
32 concat!(file!(), ":", line!())
33 };
34}