mod_idiom

Crates.iomod_idiom
lib.rsmod_idiom
version0.1.1
created_at2025-07-26 10:40:43.747078+00
updated_at2025-07-26 11:13:37.845382+00
description`mod` and `use` idiom.
homepage
repositoryhttps://github.com/nossie531/mod_idiom
max_upload_size
id1769052
size17,456
(nossie531)

documentation

README

mod_idiom

mod and use idiom.

The author of this crate is not good at English.
Forgive me if the document is hard to read.

What is this?

This crate provides a macro for common usage of mod and use.

Background

In Rust, when dividing code into multiple files, first treat the files as modules with mod, and then access each item inside the module with use. This approach is very flexible.

However, this approach will be redundant, if you just want to separate items into files and do not plan to access them as modules from multiple locations. In this case, file name is required twice.

Examples

Without this crate.

mod my_items;
pub use my_items::*;

With this crate.

m::u!(pub mod my_items);

Note: m is shorthand by Cargo.toml.

Other options

There are many crates that can do the same thing.

Followings are some of them.

📦 mod_use - Supports bulk targeting.
📦 moddef - Supports bulk targeting, public level adjustment, etc.
📦 export-magic - Supports public level adjustment.

Highlights

This crate has no functional advantages compared to others.
(Furthermore, this crate does not support bulk targeting.)

Therefore the rest is all about names and notation.
In other words, it's just a matter of style preference.
I hope this crate fits your style...

TIPS (shorthand name)

Item imports are boilerplate, so you'll want to keep them short. This can be achieved by changing crate name when introducing it in Cargo.toml as follows.

[dependencies]
m = { package = "mod_idiom", version = "0.1" }

History

See CHANGELOG.

Commit count: 0

cargo fmt