]> git.proxmox.com Git - proxmox-backup.git/commitdiff
define macro for propertymap
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 2 Nov 2018 08:44:18 +0000 (09:44 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 2 Nov 2018 08:44:18 +0000 (09:44 +0100)
src/json_schema.rs
src/main.rs

index da292c9736fac862feed162e64def6b1c0c641ca..6456c72c8f2a0fbf9f6010ad8eb074024bddc05f 100644 (file)
@@ -131,3 +131,14 @@ pub static PVE_VMID: Jss = Integer!{
     description => "The (unique) ID of the VM.",
     minimum => Some(1)
 };
+
+#[macro_export]
+macro_rules! propertymap {
+    ($($name:ident => $e:expr),*) => {
+        PropertyMap {
+            entries: &[
+                $( ( stringify!($name),  $e), )*
+            ]
+        }
+    }
+}
index 08336b6afe36e74c01c91cd398cd602f569e28c1..b7918ee10442d449db941f668369b60fb786c22c 100644 (file)
@@ -18,44 +18,40 @@ use hyper::{Method, Body, Request, Response, Server, StatusCode};
 use hyper::rt::Future;
 use hyper::service::service_fn_ok;
 
-static PARAMETERS1: PropertyMap = PropertyMap {
-    entries: &[
-        ("force", Boolean!{
-            description => "Test for boolean options."
-        }),
-        ("text1", ApiString!{
-            description => "A simple text string.",
-            min_length => Some(10),
-            max_length => Some(30)
-        }),
-        ("count", Integer!{
-            description => "A counter for everything.",
-            minimum => Some(0),
-            maximum => Some(10)
-        }),
-        ("myarray1", Array!{
-            description => "Test Array of simple integers.",
-            items => &PVE_VMID
-        }),
-        ("myarray2", Jss::Array(JssArray {
-            description: "Test Array of simple integers.",
-            optional: Some(false),
-            items: &Object!{description => "Empty Object."},
-        })),
-        ("myobject", Object!{
-            description => "TEST Object.",
-            properties => &PropertyMap {
-                entries: &[
-                    ("vmid", Jss::Reference { reference: &PVE_VMID}),
-                    ("loop", Integer!{
-                        description => "Totally useless thing.",
-                        optional => Some(false)
-                    })
-                ]
+static PARAMETERS1: PropertyMap = propertymap!{
+    force => Boolean!{
+        description => "Test for boolean options."
+    },
+    text1 => ApiString!{
+        description => "A simple text string.",
+        min_length => Some(10),
+        max_length => Some(30)
+    },
+    count => Integer!{
+        description => "A counter for everything.",
+        minimum => Some(0),
+        maximum => Some(10)
+    },
+    myarray1 => Array!{
+        description => "Test Array of simple integers.",
+        items => &PVE_VMID
+    },
+    myarray2 => Jss::Array(JssArray {
+        description: "Test Array of simple integers.",
+        optional: Some(false),
+        items: &Object!{description => "Empty Object."},
+    }),
+    myobject => Object!{
+        description => "TEST Object.",
+        properties => &propertymap!{
+            vmid => Jss::Reference { reference: &PVE_VMID},
+            loop => Integer!{
+                description => "Totally useless thing.",
+                optional => Some(false)
             }
-        }),
-        ("emptyobject", Object!{description => "Empty Object."}),
-    ]
+        }
+    },
+    emptyobject => Object!{description => "Empty Object."}
 };
 
 
@@ -87,13 +83,11 @@ fn test_api_handler(param: Value) -> Result<Value, Error> {
 
 static TEST_API_METHOD: ApiMethod = ApiMethod {
     description: "This is a simple test.",
-    properties: &PropertyMap {
-        entries: &[
-            ("force", Boolean!{
-                optional => Some(true),
-                description => "Test for boolean options."
-            })
-        ]
+    properties: &propertymap!{
+        force => Boolean!{
+            optional => Some(true),
+            description => "Test for boolean options."
+        }
     },
     returns: &Jss::Null,
     handler: test_api_handler,