hypermod

Crates.iohypermod
lib.rshypermod
version0.2.0
sourcesrc
created_at2022-02-24 15:25:58.96942
updated_at2022-08-04 05:09:38.596795
descriptionAutomatically build the module tree from the src/ dir.
homepage
repositoryhttps://github.com/willhodges/hypermod
max_upload_size
id538582
size17,894
(willhodges)

documentation

README

Hypermod

An even lazier version of automod and supermod. Searches the src/ directory recursively for .rs files, then builds a module tree using the directory names as module names, allowing us to never write another mod statement again so long as we live. This mimics Java package namespaces, which are also mapped to the project directory structure.

Syntax

In the project's main.rs or lib.rs: hypermod::hypermod!();

Example

Assume the following project directory structure:

  • my_rust_project/
    • src/
      • db/
        • migrations/
          • 01-migration/
            • up.sql
            • down.sql
        • schema.rs
      • model/
        • bar.rs
        • foo.rs
      • baz.rs
      • main.rs

The call to the hypermod!() macro in main.rs or lib.rs expands to the following mod statements and use statements:

mod db {
    mod schema;
    pub use self::schema::*; 
}
mod model {
    mod bar;
    pub use self::bar::*; 
    mod foo;
    pub use self::foo::*; 
}
mod baz;
pub use self::baz::*;

This allows the developer to skip writing mod statements and instead use any pub item in a Rust source file through the names of the subdirectories in which it is located. For example:

use crate::model::BarStruct;
use crate::db::schema_function;

License

This software is licensed under either of the following:

Any contribution you intentionally submit for inclusion in the work, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.

Commit count: 3

cargo fmt