From 183125b1cd13bd7b46410c4ad107a11daf60df16 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 18 Jul 2019 15:05:26 +0200 Subject: [PATCH] macro: named struct: allow short form for fields Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api_macro.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/proxmox-api-macro/src/api_macro.rs b/proxmox-api-macro/src/api_macro.rs index 327308eb..8d18496e 100644 --- a/proxmox-api-macro/src/api_macro.rs +++ b/proxmox-api-macro/src/api_macro.rs @@ -539,10 +539,20 @@ fn handle_named_struct_fields( .remove(&name_str) .ok_or_else(|| { c_format_err!(name.span(), "missing field in definition: '{}'", name_str) - })? - .expect_object()?; + })?; + + let def = match def { + Expression::Expr(syn::Expr::Lit(lit)) => match lit.lit { + syn::Lit::Str(description) => ParameterDefinition::builder() + .description(Some(description)) + .build() + .unwrap(), + other => c_bail!(other.span(), "expected description as literal string"), + }, + Expression::Object(obj) => ParameterDefinition::from_object(obj)?, + other => c_bail!(other.span(), "expected description or field definition"), + }; - let def = ParameterDefinition::from_object(def)?; def.add_verifiers(&name_str, this, &mut verify_entries); }