From a5e1a1c36f80bf7ad1ab85ab08375025e28303d1 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sun, 28 Jun 2026 21:20:41 +1000 Subject: [PATCH 1/2] chore: internal implementation improvements --- CHANGES.md | 5 ++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/diagnostics/mod.rs | 10 +--- src/lib.rs | 1 + src/macros.rs | 108 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 src/macros.rs diff --git a/CHANGES.md b/CHANGES.md index 44f0786..36df5e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ # Diagnosticism.Rust - CHANGES +## 0.3.1 - 28th June 2026 + +* internal implementation improvements; + + ## 0.3.0 - 27th June 2026 * added `nanoseconds_to_string()` — compact human-readable duration formatting (behaviour matches **Diagnosticism.Python** 0.16.0); diff --git a/Cargo.lock b/Cargo.lock index 18899c5..36586bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -206,7 +206,7 @@ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "diagnosticism" -version = "0.3.0" +version = "0.3.1" dependencies = [ "criterion", "rand", diff --git a/Cargo.toml b/Cargo.toml index f458600..b479698 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ name = "diagnosticism" readme = "README.md" repository = "https://github.com/synesissoftware/Diagnosticism.Rust" rust-version = "1.74" -version = "0.3.0" +version = "0.3.1" # ########################################################## diff --git a/src/diagnostics/mod.rs b/src/diagnostics/mod.rs index cfb00e6..1d9f5c8 100644 --- a/src/diagnostics/mod.rs +++ b/src/diagnostics/mod.rs @@ -1,14 +1,6 @@ // diagnostics/mod.rs -macro_rules! declare_and_publish { - ($mod_name:ident, $($type_name:ident),* $(,)?) => { - mod $mod_name; - - pub use $mod_name::{ - $($type_name),* - }; - }; -} +use crate::macros::declare_and_publish; declare_and_publish!(debug_squeezer, DebugSqueezer); declare_and_publish!(doomgram, DoomGram, doom_scope); diff --git a/src/lib.rs b/src/lib.rs index dac1d8b..edf5b99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,6 +91,7 @@ // lib.rs pub mod diagnostics; +pub(crate) mod macros; pub use diagnostics::{ doom_scope, diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..24dfa9e --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,108 @@ +macro_rules! declare_and_publish_impl_ { + ($mod_name:ident; $($construct_name:ident),*; $vis:vis) => { + mod $mod_name; + + $vis use $mod_name::{ $($construct_name),* }; + }; +} + +/// Declares a private submodule and re-exports selected items from it. +/// +/// Use in a **`mod.rs` barrel file** when a directory contains sibling +/// `.rs` implementation files. Each invocation replaces: +/// +/// ```rust,ignore +/// mod margin; +/// pub use margin::margin; +/// ``` +/// +/// with a single macro call. The first argument is the **module name** +/// (matching `name.rs` or `name/mod.rs`); remaining arguments are **item +/// names** (types, functions, constants) to re-export from that module. +/// +/// # Setup +/// +/// ```rust,ignore +/// use crate::macros::declare_and_publish; +/// ``` +/// +/// # Forms +/// +/// * `declare_and_publish!(mod_name, Item)` — `pub use` (default); +/// * `declare_and_publish!(pub mod_name, Item)` — `pub use` (explicit); +/// * `declare_and_publish!(crate mod_name, Item)` — `pub(crate) use`; +/// * `declare_and_publish!(super mod_name, Item)` — `pub(super) use`; +/// * `declare_and_publish!(self mod_name, Item)` — `pub(self) use`; +/// * `declare_and_publish!(priv mod_name, Item)` — `pub(self) use` (synonym); +/// * `declare_and_publish!($vis mod_name, Item)` — any Rust visibility +/// (e.g. `pub(crate)`, `pub(in crate::api)`). +/// +/// Multiple items may be re-exported from one module: +/// +/// ```rust,ignore +/// declare_and_publish!(doomgram, DoomGram, doom_scope); +/// ``` +/// +/// A parent module (including **`lib.rs`**) may aggregate a child barrel: +/// +/// ```rust,ignore +/// declare_and_publish!( +/// api, +/// evaluate_scalar_eq_approx, +/// margin, +/// ); +/// ``` +/// +/// # Examples +/// +/// Public API surface: +/// +/// ```rust,ignore +/// declare_and_publish!(password, Password); +/// declare_and_publish!( +/// time_format, +/// NanosecondsStr, +/// nanoseconds_to_string, +/// ); +/// ``` +/// +/// Crate-internal wiring: +/// +/// ```rust,ignore +/// declare_and_publish!(crate compare, compare_foo, compare_bar); +/// ``` +/// +/// Submodules that need no re-export remain ordinary private declarations: +/// +/// ```rust,ignore +/// mod flf; +/// ``` +macro_rules! declare_and_publish { + (crate $mod_name:ident $(, $construct_name:ident)* $(,)?) => { + $crate::macros::declare_and_publish_impl_!($mod_name; $($construct_name),*; pub(crate)); + }; + (pub $mod_name:ident $(, $construct_name:ident)* $(,)?) => { + $crate::macros::declare_and_publish_impl_!($mod_name; $($construct_name),*; pub); + }; + (priv $mod_name:ident $(, $construct_name:ident)* $(,)?) => { + $crate::macros::declare_and_publish_impl_!($mod_name; $($construct_name),*; pub(self)); + }; + (self $mod_name:ident $(, $construct_name:ident)* $(,)?) => { + $crate::macros::declare_and_publish_impl_!($mod_name; $($construct_name),*; pub(self)); + }; + (super $mod_name:ident $(, $construct_name:ident)* $(,)?) => { + $crate::macros::declare_and_publish_impl_!($mod_name; $($construct_name),*; pub(super)); + }; + ($mod_name:ident $(, $construct_name:ident)* $(,)?) => { + $crate::macros::declare_and_publish_impl_!($mod_name; $($construct_name),*; pub); + }; + ($vis:vis $mod_name:ident $(, $construct_name:ident)* $(,)?) => { + $crate::macros::declare_and_publish_impl_!($mod_name; $($construct_name),*; $vis); + }; +} + +pub(crate) use declare_and_publish; +pub(crate) use declare_and_publish_impl_; + + +// ///////////////////////////// end of file //////////////////////////// // From ee1d139367fdadfe3eeeeb29b19293395bb36ddc Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sun, 28 Jun 2026 21:25:45 +1000 Subject: [PATCH 2/2] fix --- src/macros.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/macros.rs b/src/macros.rs index 24dfa9e..96501c1 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -33,7 +33,8 @@ macro_rules! declare_and_publish_impl_ { /// * `declare_and_publish!(crate mod_name, Item)` — `pub(crate) use`; /// * `declare_and_publish!(super mod_name, Item)` — `pub(super) use`; /// * `declare_and_publish!(self mod_name, Item)` — `pub(self) use`; -/// * `declare_and_publish!(priv mod_name, Item)` — `pub(self) use` (synonym); +/// * `declare_and_publish!(priv mod_name, Item)` — `pub(self) use` +/// (synonym); /// * `declare_and_publish!($vis mod_name, Item)` — any Rust visibility /// (e.g. `pub(crate)`, `pub(in crate::api)`). ///