#module #import #all #import-all

import-modules

import-modules 是一个基于 require-all 的库

7 个版本 (1 个稳定版本)

1.0.0 2023年8月9日
0.1.5 2023年6月18日

#471过程宏

Download history 30/week @ 2024-03-31

每月67次下载

MIT 许可证

14KB
194

import-modules

描述

import-modules 是一个基于 require-all 的库

示例

这是基于 import-modules 测试目录的。

中间过程和后处理

中间过程允许您操纵模块的处理方式。

输入

use import_macro::import;

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

输出

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

模块

类似于中间过程,它默认将其作为Rust模块导入。

输入

use import_macro::import;

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

输出

mod math;

作者

变更日志

1.0.0 - 新的导入

所有宏都已删除。而是使用新的 import 宏,该宏使用JSON配置。以下是有效的配置

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

许可证

本项目采用 MIT 许可证。

依赖

~4–6MB
~107K SLoC