| Crates.io | mod_idiom |
| lib.rs | mod_idiom |
| version | 0.1.1 |
| created_at | 2025-07-26 10:40:43.747078+00 |
| updated_at | 2025-07-26 11:13:37.845382+00 |
| description | `mod` and `use` idiom. |
| homepage | |
| repository | https://github.com/nossie531/mod_idiom |
| max_upload_size | |
| id | 1769052 |
| size | 17,456 |
mod and use idiom.
The author of this crate is not good at English.
Forgive me if the document is hard to read.
This crate provides a macro for common usage of mod and use.
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.
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.
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.
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...
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" }
See CHANGELOG.