Automatically build a Rust module tree from the project directory structure

Related tags

Utilities hypermod
Overview

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.

You might also like...
Automatically cross-compiles the sysroot crates core, compiler_builtins, and alloc.

cargo-xbuild Cargo-xbuild is a wrapper for cargo build, which cross compiles the sysroot crates core, compiler_builtins, and alloc for custom targets.

Automatically transform your Next.js Pages to use SuperJSON with SWC

🔌 NEXT SUPERJSON PLUGIN export default function Page({ date }) { return ( div Today is {date.toDateString()} /div ) } // You c

A CLI tool that automatically writes commit messages for you.
A CLI tool that automatically writes commit messages for you.

Automagically-generated commit messages A CLI tool that generates commit messages from your staged changes, built in Rust and using OpenAI's Codex. In

A swc plugin that automatically converts React component libraries into "React Client Component"

A swc plugin that automatically converts React component libraries into "React Client Component". For example, you can automatically convert components from @mui into "React Client Component" without having to wrap a component that uses "use client".

Rust library to scan files and expand multi-file crates source code as a single tree

syn-file-expand This library allows you to load full source code of multi-file crates into a single syn::File. Features: Based on syn crate. Handling

A balanced unbounded interval-tree in Rust with associated values in the nodes

store-interval-tree A balanced unbounded interval-tree in Rust with associated values in the nodes. Based on rudac and bio. Example use store_interval

Render cargo dependency tree in online

Cargo Tree Online Check out rendered page Render cargo dependency tree in online. Usage trunk serve Copy and paste the content of Cargo.lock file to

tree-sitter server for kakoune

tree-sitter.kak Warning This currently just a proof-of-concept, and isn't stable yet. A Tree-sitter server that keeps parsed ASTs in memory. This is u

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.
Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Owner
null
File Tree Fuzzer allows you to create a pseudo-random directory hierarchy filled with some number of files.

FTZZ File Tree Fuzzer allows you to create a pseudo-random directory hierarchy filled with some number of files. Installation $ cargo +nightly install

Alex Saveau 22 Dec 28, 2022
Count lines from files in a directory.

rust-cloc Count lines from files in a directory. Features Count the number of empty and non-empty lines in total from all files in a directory. Count

Daniel Liu 2 Apr 27, 2022
A naive buffered/sync channel implementation in Rust, using the queue data structure

buffered-queue-rs Introduction This is my attempt at a simple and very naive buffered/synced queue implementation in Rust. The base thread-safe queue

Dhruv 4 Jul 22, 2023
A timer based on a multi-time wheel structure

wheel-timer2 A timer based on a multi-time wheel structure This library uses a multi-layered time wheel structure. When a task is added to the wheel,

orange soeur 1 Jan 25, 2022
Example of executing ES module exports from Rust

rusty_esm This is an example showcasing a common use case for embedding Deno - calling JS module exports from Rust. The rest is pretty self explainato

Divy Srivastava 9 Dec 13, 2022
Pure rust implementation of python's random module with compatible generator behaviour.

pyrand Pure rust implementation of (parts of) python's random module with compatible PRNG behaviour: seeding with equivalent values will yield identic

Stefan V. 4 Feb 10, 2024
A module for masscan

A module for masscan

w01fb0ss 5 Jul 14, 2022
A lightning fast state management module for Yew.

yewv A lightning fast state management module for Yew built with performance and simplicity as a first priority. Who is this for? If you wish to use a

null 7 Dec 8, 2022
Crate of GitHub’s collection of gitignores, embedded, automatically updated

Gitignores GitHub’s collection of gitignores, embedded, automatically updated. API documentation. Public Domain via CC0-1.0 (same as source data). MSR

null 3 May 3, 2022
A git hook to manage derivative files automatically.

git-derivative A git hook to manage derivative files automatically. For example if you checked out to a branch with different yarn.lock, git-derivativ

Sung Jeon 3 Oct 30, 2022