Repository: rust-bitcoin/rust-bitcoin
Pull request #211 (2019-01-15 16:16:59)

Internalize unnecessarily exported macros
`user_enum` didn't need to be exported as per IRC convo.


Patch:
diff --git a/src/internal_macros.rs b/src/internal_macros.rs
index afb66580..6af38a46 100644
--- a/src/internal_macros.rs
+++ b/src/internal_macros.rs
@@ -12,6 +12,10 @@
 // If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
 //
 
+//! Internal Macros
+//!
+//! Macros meant to be used inside the Rust Bitcoin library
+
 macro_rules! impl_consensus_encoding {
     ($thing:ident, $($field:ident),+) => (
         impl<S: ::consensus::encode::Encoder> ::consensus::encode::Encodable<S> for $thing {
@@ -416,3 +420,107 @@ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
         }
     )
 }
+
+macro_rules! user_enum {
+    (
+        $(#[$attr:meta])*
+        pub enum $name:ident {
+            $(#[$doc:meta]
+              $elem:ident <-> $txt:expr),*
+        }
+    ) => (
+        $(#[$attr])*
+        pub enum $name {
+            $(#[$doc] $elem),*
+        }
+
+        impl ::std::fmt::Debug for $name {
+            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+                f.pad(match *self {
+                    $($name::$elem => $txt),*
+                })
+            }
+        }
+
+        impl ::std::fmt::Display for $name {
+            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+                f.pad(match *self {
+                    $($name::$elem => $txt),*
+                })
+            }
+        }
+
+        impl ::std::str::FromStr for $name {
+            type Err = ::std::io::Error;
+            #[inline]
+            fn from_str(s: &str) -> Result<Self, Self::Err> {
+                match s {
+                    $($txt => Ok($name::$elem)),*,
+                    _ => Err(::std::io::Error::new(
+                        ::std::io::ErrorKind::InvalidInput,
+                        format!("Unknown network (type {})", s),
+                    )),
+                }
+            }
+        }
+
+        #[cfg(feature = "serde")]
+        impl<'de> $crate::serde::Deserialize<'de> for $name {
+            #[inline]
+            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+            where
+                D: $crate::serde::Deserializer<'de>,
+            {
+                use $crate::std::fmt::{self, Formatter};
+
+                struct Visitor;
+                impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
+                    type Value = $name;
+
+                    fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
+                        formatter.write_str("an enum value")
+                    }
+
+                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
+                    where
+                        E: $crate::serde::de::Error,
+                    {
+                        static FIELDS: &'static [&'static str] = &[$(stringify!($txt)),*];
+
+                        $( if v == $txt { Ok($name::$elem) } )else*
+                        else {
+                            Err(E::unknown_variant(v, FIELDS))
+                        }
+                    }
+
+                    fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
+                    where
+                        E: $crate::serde::de::Error,
+                    {
+                        self.visit_str(v)
+                    }
+
+                    fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
+                    where
+                        E: $crate::serde::de::Error,
+                    {
+                        self.visit_str(&v)
+                    }
+
+                }
+
+                deserializer.deserialize_str(Visitor)
+            }
+        }
+
+        #[cfg(feature = "serde")]
+        impl ::serde::Serialize for $name {
+            fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+            where
+                S: ::serde::Serializer,
+            {
+                serializer.serialize_str(&self.to_string())
+            }
+        }
+    );
+}
diff --git a/src/lib.rs b/src/lib.rs
index 5311f617..362f0591 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -58,7 +58,6 @@
 #[macro_use]
 mod internal_macros;
 #[macro_use]
-pub mod macros;
 pub mod network;
 pub mod blockdata;
 pub mod util;
@@ -82,4 +81,4 @@
 pub use util::decimal::UDecimal;
 
 #[cfg(feature = "fuzztarget")]
-pub mod fuzz_util;
\ No newline at end of file
+pub mod fuzz_util;
diff --git a/src/macros.rs b/src/macros.rs
deleted file mode 100644
index 718d4ae5..00000000
--- a/src/macros.rs
+++ /dev/null
@@ -1,123 +0,0 @@
-// Rust Bitcoin Library
-// Written in 2014 by
-//     Andrew Poelstra <apoelstra@wpsoftware.net>
-//
-// To the extent possible under law, the author(s) have dedicated all
-// copyright and related and neighboring rights to this software to
-// the public domain worldwide. This software is distributed without
-// any warranty.
-//
-// You should have received a copy of the CC0 Public Domain Dedication
-// along with this software.
-// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
-//
-
-//! Macros
-//!
-//! Macros available to users of the Bitcoin library
-
-#[macro_export]
-macro_rules! user_enum {
-    (
-        $(#[$attr:meta])*
-        pub enum $name:ident {
-            $(#[$doc:meta]
-              $elem:ident <-> $txt:expr),*
-        }
-    ) => (
-        $(#[$attr])*
-        pub enum $name {
-            $(#[$doc] $elem),*
-        }
-
-        impl ::std::fmt::Debug for $name {
-            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
-                f.pad(match *self {
-                    $($name::$elem => $txt),*
-                })
-            }
-        }
-
-        impl ::std::fmt::Display for $name {
-            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
-                f.pad(match *self {
-                    $($name::$elem => $txt),*
-                })
-            }
-        }
-
-        impl ::std::str::FromStr for $name {
-            type Err = ::std::io::Error;
-            #[inline]
-            fn from_str(s: &str) -> Result<Self, Self::Err> {
-                match s {
-                    $($txt => Ok($name::$elem)),*,
-                    _ => Err(::std::io::Error::new(
-                        ::std::io::ErrorKind::InvalidInput,
-                        format!("Unknown network (type {})", s),
-                    )),
-                }
-            }
-        }
-
-        #[cfg(feature = "serde")]
-        impl<'de> $crate::serde::Deserialize<'de> for $name {
-            #[inline]
-            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
-            where
-                D: $crate::serde::Deserializer<'de>,
-            {
-                use $crate::std::fmt::{self, Formatter};
-
-                struct Visitor;
-                impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
-                    type Value = $name;
-
-                    fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
-                        formatter.write_str("an enum value")
-                    }
-
-                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
-                    where
-                        E: $crate::serde::de::Error,
-                    {
-                        static FIELDS: &'static [&'static str] = &[$(stringify!($txt)),*];
-
-                        $( if v == $txt { Ok($name::$elem) } )else*
-                        else {
-                            Err(E::unknown_variant(v, FIELDS))
-                        }
-                    }
-
-                    fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
-                    where
-                        E: $crate::serde::de::Error,
-                    {
-                        self.visit_str(v)
-                    }
-
-                    fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
-                    where
-                        E: $crate::serde::de::Error,
-                    {
-                        self.visit_str(&v)
-                    }
-
-                }
-
-                deserializer.deserialize_str(Visitor)
-            }
-        }
-
-        #[cfg(feature = "serde")]
-        impl ::serde::Serialize for $name {
-            fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
-            where
-                S: ::serde::Serializer,
-            {
-                serializer.serialize_str(&self.to_string())
-            }
-        }
-    );
-}
-


Test patch:
diff --git a/src/test_macros.rs b/src/test_macros.rs
index b2e9cafc..6bf5e3dd 100644
--- a/src/test_macros.rs
+++ b/src/test_macros.rs
@@ -16,7 +16,6 @@
 //!
 //! Internal macros used for unit tests
 
-#[macro_export]
 #[cfg(all(feature = "serde", feature = "strason"))]
 macro_rules! serde_round_trip (
     ($var:expr) => ({