{"id":21576356,"url":"https://github.com/sigurd4/moddef","last_synced_at":"2025-04-30T20:07:12.159Z","repository":{"id":178489482,"uuid":"657681078","full_name":"sigurd4/moddef","owner":"sigurd4","description":"Macro for convenient module declaration. Each module can be put in a group, and visibility can be applied to the whole group with ease.","archived":false,"fork":false,"pushed_at":"2024-12-29T04:03:21.000Z","size":31,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T20:07:07.128Z","etag":null,"topics":["crate","declaration","ease-of-use","flat","flattening","group","grouped","groups","macro","mod","module","modules","nested","re-exports","rust","structure"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/moddef","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sigurd4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-23T15:36:44.000Z","updated_at":"2025-04-28T01:24:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"d2d9c969-8d03-4255-a11d-2aea2fb81a31","html_url":"https://github.com/sigurd4/moddef","commit_stats":null,"previous_names":["sigurd4/moddef"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigurd4%2Fmoddef","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigurd4%2Fmoddef/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigurd4%2Fmoddef/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigurd4%2Fmoddef/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sigurd4","download_url":"https://codeload.github.com/sigurd4/moddef/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251774895,"owners_count":21641731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crate","declaration","ease-of-use","flat","flattening","group","grouped","groups","macro","mod","module","modules","nested","re-exports","rust","structure"],"created_at":"2024-11-24T12:16:15.295Z","updated_at":"2025-04-30T20:07:12.140Z","avatar_url":"https://github.com/sigurd4.png","language":"Rust","readme":"# moddef\nOrganize your module declaration with this simple macro.\n\n## Why?\n\nI just hated writing the same stuff over and over again.\n\n## Example\n\nWith `moddef`, you can write your module declarations like this:\n\n```rust\nmoddef::moddef!(\n    flat(pub) mod {\n        maybe_rtf_or_system,\n        maybe_system,\n        rtf_or_system,\n        system,\n        validate_filter_bands\n    },\n    pub mod {\n        analysis,\n        decompositions,\n        gen,\n        identification,\n        operations,\n        quantities,\n        systems,\n        transforms,\n        util,\n        windows\n    },\n    mod {\n        plot for cfg(test)\n    }\n);\n```\n\nInstead of this:\n\n```rust\nmod maybe_rtf_or_system; pub use maybe_rtf_or_system::*;\nmod maybe_system; pub use maybe_system::*;\nmod rtf_or_system; pub use rtf_or_system::*;\nmod system; pub use system::*;\nmod validate_filter_bands; pub use validate_filter_bands::*;\n\npub mod analysis;\npub mod decompositions;\npub mod gen;\npub mod identification;\npub mod operations;\npub mod quantities;\npub mod systems;\npub mod transforms;\npub mod util;\npub mod windows\n\n#[cfg(test)]\nmod plot;\n```\n\nThe two are equivalent, but, since i prefer the first one, i wrote a macro to do it easily, which i use in every project of mine. It's really just personal preference.\n\nI find it makes it a lot easier when i have a lot of modules with similar properties, and especially when i want to rename a module, since its name only has to be written once when i re-export (which i do often).\n\n## Structure\n\nThe schema used for the macro is like this:\n\n```txt\n$MODULE_VISIBLITY mod {\n    $MODULE_NAME,\n    ...\n    // or:\n    $MODULE_NAME for $MODULE_ATTRIBUTES, // the trailing comma is optional\n    ...\n},\n...\n// Alternatively, for just a single module:\n$MODULE_VISIBLITY mod $MODULE_NAME,\n...\n// or\n$MODULE_VISIBILITY mod $MODULE_NAME for $MODULE_ATTRIBUTES, // The trailing comma here is also optional\n```\n\nTrailing commas are optional, but comma-seperators are not.\n\n## Module visibility\n\nBefore the `mod` token, a descriptor can be chosen to set the visibility of the module, and wether or not the module should be \"flat\".\n\nFlatness of a module is something i just made up, but it means that the inner members of the module will be re-exported, and from the outside, seem as if they belong to the parent module. I just do this a lot, so i gave it a name and a quick shortcut within the macro.\n\nHere are some examples of valid module visibility descriptors:\n\n- Private\n    - Equivalent to `mod mymodule;`\n- `pub` Public\n    - Equivalent to `pub mod mymodule;`\n- `pub(crate)` Crate-wide\n    - Equivalent to `pub(crate) mod mymodule;`\n- `pub(self)` Local\n    - Equivalent to `pub(self) mod mymodule;`\n- `pub(super)` One-layer up in module tree\n    - Equivalent to `pub(super) mod mymodule;`\n- `flat` Private with members privately re-exported\n    - Equivalent to `mod mymodule; use mymodule::*;`\n- `flat(pub)` Private with members publicly re-exported\n    - Equivalent to `mod mymodule; pub use mymodule::*;`\n- `flat(pub(crate))` Private with members re-exported crate-wide\n    - Equivalent to `mod mymodule; pub(crate) use mymodule::*;`\n- `pub flat(pub(crate))` Public with members re-exported crate-wide\n    - Equivalent to `pub mod mymodule; pub(crate) use mymodule::*;`\n\nIn short: if you don't use the `flat` descriptor, any valid visiblity descriptor in the Rust language should work fine. If you do use `flat`, a visibility to the re-export can be given in the parenthesis after.\n\n## Module attributes\n\nThis is just a whitespace-separated list of attributes that will be appended within a `#[...]` before the module when the macro expands. I often use `cfg(test)` to tell the compiler to ignore the module when not compiling tests.\n\nIf attributes are to be given, a single `for` token must be applied after the module name.\n\n### Example\n\n```rust\nmoddef::moddef!(\n    flat mod {\n        impl_macos for cfg(target_os = \"macos\"),\n        impl_linux for cfg(target_os = \"linux\") cfg(feature = \"std\")),\n        impl_windows for cfg(target_os = \"windows\"),\n        impl_linux_nostd for cfg(target_os = \"linux\") cfg(not(feature = \"std\")))\n    }\n);\n```\n\n## Note\n\nIf the macro fails to do anything given in the documentation it is a bug. It can maybe do other things, like assign visibility to each module in a module-group seperately (at least it can right now, as of writing this), but those are really just implementation details that i needed to make the macro work. They're not specified features.\n\nI hope this helps. I've used this macro for a long time, but i think other people should be able to try it. There's not much point in publishing code that only you yourself know how to use. Enjoy.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigurd4%2Fmoddef","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigurd4%2Fmoddef","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigurd4%2Fmoddef/lists"}