[librsvg: 5/15] property_macros: factor out duplicated code



commit 29c6cf47b7da8855b4c8de9821b960545911c0d6
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Apr 7 10:24:47 2018 +0200

    property_macros: factor out duplicated code

 rsvg_internals/src/property_macros.rs | 54 ++++++++++++-----------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
---
diff --git a/rsvg_internals/src/property_macros.rs b/rsvg_internals/src/property_macros.rs
index 1a39de00..b36a389a 100644
--- a/rsvg_internals/src/property_macros.rs
+++ b/rsvg_internals/src/property_macros.rs
@@ -38,17 +38,8 @@ macro_rules! make_property {
             $($variant),+
         }
 
-        impl Default for $name {
-            fn default() -> $name {
-                $name::$default
-            }
-        }
-
-        impl ::property_macros::Property for $name {
-            fn inherits_automatically() -> bool {
-                $inherits_automatically
-            }
-        }
+        impl_default!($name, $name::$default);
+        impl_property!($name, $inherits_automatically);
 
         impl ::parsers::Parse for $name {
             type Data = ();
@@ -72,17 +63,8 @@ macro_rules! make_property {
         #[derive(Debug, Clone, PartialEq)]
         pub struct $name(pub $type);
 
-        impl Default for $name {
-            fn default() -> $name {
-                $name($default)
-            }
-        }
-
-        impl ::property_macros::Property for $name {
-            fn inherits_automatically() -> bool {
-                $inherits_automatically
-            }
-        }
+        impl_default!($name, $name($default));
+        impl_property!($name, $inherits_automatically);
 
         impl ::parsers::Parse for $name {
             type Data = ();
@@ -107,17 +89,8 @@ macro_rules! make_property {
         #[derive(Debug, Clone, PartialEq)]
         pub struct $name(pub $type);
 
-        impl Default for $name {
-            fn default() -> $name {
-                $name($default)
-            }
-        }
-
-        impl ::property_macros::Property for $name {
-            fn inherits_automatically() -> bool {
-                $inherits_automatically
-            }
-        }
+        impl_default!($name, $name($default));
+        impl_property!($name, $inherits_automatically);
     };
 
     ($name: ident,
@@ -130,14 +103,23 @@ macro_rules! make_property {
             $(pub $field_name: $field_type),+
         }
 
+        impl_default!($name, $name { $($field_name: $field_default),+ });
+        impl_property!($name, $inherits_automatically);
+    };
+}
+
+macro_rules! impl_default {
+    ($name: ident, $default: expr) => {
         impl Default for $name {
             fn default() -> $name {
-                $name {
-                    $($field_name: $field_default),+
-                }
+                $default
             }
         }
+    };
+}
 
+macro_rules! impl_property {
+    ($name: ident, $inherits_automatically: expr) => {
         impl ::property_macros::Property for $name {
             fn inherits_automatically() -> bool {
                 $inherits_automatically


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]