#module #list #macro #name #generate #relative-path

macro list-modules

A procedural macro for generating a list of string slices of the names of the modules inside a source code directory of a project

4 releases

0.1.6 Apr 16, 2023
0.1.5 Apr 16, 2023

#521 in Procedural macros

33 downloads per month

GPL-3.0-or-later

7KB

List-Modules Procedural Macro

This macro creates a constant string slice list of all the module names which are children of an indicated crate module folder. Paths are specified relative to the cargo manifest directory.

For example, calling this macro from mod.rs in the following file tree with list_modules::here!("parent/");...

parent/
    mod.rs
    child_1.rs
    child_2/
        mod.rs
        internal.rs
        other_internal/
            ...
        ...
    child_3.rs
    child_4.rs
    ...
    child_N/
        mod.rs

...will result in the following list expansion:

pub const LIST: [&str; N] = [
    "child_1",
    "child_2",
    "child_3",
    ...
    "child_N",
];

Note that this is the only guaranteed behavior.


lib.rs:

List-Modules Procedural Macro

This macro creates a constant string slice list of all the module names which are children of an indicated crate module folder. Paths are specified relative to the cargo manifest directory.

For example, calling this macro from mod.rs in the following file tree with list_modules::here!("parent/");...

parent/
    mod.rs
    child_1.rs
    child_2/
        mod.rs
        internal.rs
        other_internal/
            ...
        ...
    child_3.rs
    child_4.rs
    ...
    child_N/
        mod.rs

...will result in the following list expansion:

pub const LIST: [&str; N] = [
    "child_1",
    "child_2",
    "child_3",
    ...
    "child_N",
];

Note that this is the only guaranteed behavior.

Dependencies

~325–780KB
~19K SLoC