#module #import #all #import-all

macro import-modules

import-modules is a library based on require-all

7 releases (1 stable)

1.0.0 Aug 9, 2023
0.1.5 Jun 18, 2023

#325 in Procedural macros

30 downloads per month

MIT license

14KB
194 lines

import-modules

Description

import-modules is a library based on require-all

Examples

This is based on the import-modules test directory.

Inter Process and Post Process

Intermediary processes allow you to manipulate how the modules are processed.

Input

use import_macro::import;

// The {} is replaced by the module.
let functions = import!({
    "directory": "tests/math/",
    "inter_process": "math::{}::handler,",
    "post_process": "vec![{}]"
});

Output

let functions = vec![
    math::add::handler,
    math::sub::handler,
];

Module

Similar to intermediate process, this imports it by default as Rust module.

Input

use import_macro::import;

import!({
    "directory": "tests",
});

Output

mod math;

Authors

Change log

1.0.0 - The new import

All macros have been eliminated. Instead, use the new import macro, which employs JSON configuration. The following valid configuration is available:

struct Config {
    /// The directory where the modules are located.
    pub directory: String,

    /// Recursive search for modules.
    pub recursive: bool,

    /// Intermediary processes allow you to manipulate how the modules are processed.
    /// Intermediary processes replaces {} with the module.
    pub inter_process: Option<String>,

    /// Post processes allow you to manipulate how the modules are processed.
    /// Post_process replaces the with the module.
    pub post_process: Option<String>,

    /// Similar to intermediate process, this imports it by default as a public Rust module.
    pub public_module: Option<bool>,

    /// Similar to intermediate process, this imports it by default as a Rust module.
    ///
    /// Default if you don't use inter_process: true
    /// Default if you use public_module: true
    pub module: Option<bool>,

    /// Exclude files from the module list.
    ///
    /// Default: ["lib.rs", "main.rs", "mod.rs"]
    pub exclude_files: Vec<Regex>,

    /// Exclude directories from the module list.
    ///
    /// Default: [".git", ".github", "lib", "src" "tests", "target"]
    /// Note: Only if ends by directory separator.
    pub exclude_dirs: Vec<Regex>,

    /// Include files from the module list.
    pub include_files: Vec<Regex>,

    /// Include directories from the module list.
    pub include_dirs: Vec<Regex>,
}

License

This project is licensed under the MIT license.

Dependencies

~4–6MB
~107K SLoC