Repository: vks/average (language: rust)

Issue:
`concatenate!` macro cannot expand to public type
Hi,

I'd like to use `concatenate!()` and obtain a a public type, but I could not find a way.
Do you envision a simple way to do this?

Thanks


Discussion / hints:
The easiest workaround would be to use the newtype pattern to define a public type:

```rust
concatenate!(PrivateEstimator, ...);
pub struct PublicEstimator(PrivateEstimator);
```

However, this will result in quite a bit of boilerplate code. I'll consider extending `concatenate!` to support creating a public type.

Sorry for the late reply!

Fix patch:
diff --git a/src/macros.rs b/src/macros.rs
index 928f275..3190317 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -90,11 +90,11 @@ macro_rules! assert_almost_eq {
 /// ```
 #[macro_export]
 macro_rules! concatenate {
-    ( $name:ident, $([$estimator:ident, $statistic:ident]),+ ) => {
-        concatenate!( $name, $([$estimator, $statistic, $statistic]),* );
+    ( $visibility:vis $name:ident, $([$estimator:ident, $statistic:ident]),+ ) => {
+        concatenate!($visibility $name, $([$estimator, $statistic, $statistic]),* );
     };
-    ( $name:ident, $( [$estimator:ident, $field:ident, $($statistic:ident),+] ),+ ) => {
-        struct $name {
+    ( $visibility:vis $name:ident, $( [$estimator:ident, $field:ident, $($statistic:ident),+] ),+ ) => {
+        $visibility struct $name {
         $(
             $field: $estimator,
         )*


Test patch:
diff --git a/tests/integration/macros.rs b/tests/integration/macros.rs
index 4750151..350ac18 100644
--- a/tests/integration/macros.rs
+++ b/tests/integration/macros.rs
@@ -2,7 +2,7 @@
 
 use average::{concatenate, Estimate, Max, Min};
 
-concatenate!(MinMax, [Min, min], [Max, max]);
+concatenate!(pub MinMax, [Min, min], [Max, max]);
 
 #[test]
 fn concatenate_simple() {
diff --git a/tests/integration/main.rs b/tests/integration/main.rs
index 33e5870..2199f1a 100644
--- a/tests/integration/main.rs
+++ b/tests/integration/main.rs
@@ -21,3 +21,7 @@ mod skewness;
 mod streaming_stats;
 mod weighted_mean;
 mod covariance;
+
+// Ensure that the struct defined by macro is accessible
+#[allow(unused_imports)]
+use macros::MinMax;