macro_rules! mod_from {
($vis:vis $module_name:ident) => { ... };
($vis:vis $module_name:ident, $module_path_str:literal) => { ... };
}
Expand description
Declares a module by including a Rust source file relative to the project’s directory.
The macro generates a mod
declaration and inserts the contents of the specified file
into the module. This is a more ergonomic alternative to manually wrapping include!
within a module declaration.
§Usage
- To declare a module using its name:
ⓘ
// Declares `pub(super) mod helper` with contents from "helper.rs":
mod_from!(pub(super) helper);
- To declare a module with a specific path:
ⓘ
// Declares `mod helper` with contents from "src/helper.rs":
mod_from!(helper, "src/helper.rs");
See also include_from!
.