mod_idiom 0.1.1

`mod` and `use` idiom.
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented0 out of 2 items with examples
  • Size
  • Source code size: 17.45 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 99.35 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • nossie531/mod_idiom
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nossie531

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.