mods

Crates.iomods
lib.rsmods
version1.0.0
sourcesrc
created_at2020-03-14 21:27:19.40891
updated_at2020-03-14 21:27:19.40891
descriptionSimpler module declaration.
homepagehttps://github.com/nvzqz/mods
repositoryhttps://github.com/nvzqz/mods
max_upload_size
id218680
size24,049
Nikolai Vazquez (nvzqz)

documentation

https://docs.rs/mods

README

mods!

Crates.io Downloads docs.rs Build Status rustc ^1.9.0
Become a Patron! Buy me a coffee

Simpler module declaration, brought to you by @NikolaiVazquez!

This library enables you to declare modules in ways the current syntax doesn't allow.

Examples

To declare multiple public modules, simply place pub before a module list:

mods::mods! {
    pub puppy, kitty;
}

This works for all visibility modifiers:

mods::mods! {
    pub a, b;        // Visible anywhere, even outside the module
    pub(crate) c, d; // Visible anywhere within the crate
    pub(super) e, f; // Visible to the parent module
    g, h;            // Visible to the current module
}

Without the mods! macro, the same code is much less succinct. This is what the macro expands out to:

pub mod a;
pub mod b;
pub(crate) mod c;
pub(crate) mod d;
pub(super) mod e;
pub(super) mod f;
mod g;
mod h;

Installation

This crate is available on crates.io and can be used by adding the following to your project's Cargo.toml:

[dependencies]
mods = "1.0.0"

Minimum Supported Rust Version (MSRV)

This library requires Rust 1.9.0 as the minimum version and will work with all subsequent versions.

This is because previous versions can't have mod x; declarations within submodules When testing this we get an error complaining that the module file is not inside the directory "src".

Rust 2015

If you're not using Rust 2018, add this to your crate root (main.rs or lib.rs):

#[macro_use]
extern crate mods;

You can then use the macro directly from anywhere:

mods! {
    pub puppy, kitty;
}

Wishful Thinking

It would be wonderful if we could instead have:

pub mod puppy, kitty;

Or a syntax that matches use imports:

pub mod {puppy, kitty};

Changes

See CHANGELOG.md for an exhaustive list of what has changed from one version to another.

License

This project is released under either:

Commit count: 25

cargo fmt