From b81beb4dfbc4534d6b4c42d70ed508d4c0cfb34f Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 4 Dec 2019 14:27:57 +0100 Subject: [PATCH] api-macro: allow methods without return types Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api/method.rs | 8 +++++++- proxmox-api-macro/tests/ext-schema.rs | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs index d166c231..6cb32ed7 100644 --- a/proxmox-api-macro/src/api/method.rs +++ b/proxmox-api-macro/src/api/method.rs @@ -405,6 +405,12 @@ fn create_wrapper_function( // build the wrapping function: let func_name = &func.sig.ident; + + let question_mark = match func.sig.output { + syn::ReturnType::Default => None, + _ => Some(quote!(?)), + }; + wrapper_ts.extend(quote! { fn #api_func_name( mut input_params: ::serde_json::Value, @@ -413,7 +419,7 @@ fn create_wrapper_function( ) -> Result<::serde_json::Value, ::failure::Error> { if let ::serde_json::Value::Object(ref mut input_map) = &mut input_params { #body - Ok(::serde_json::to_value(#func_name(#args)?)?) + Ok(::serde_json::to_value(#func_name(#args) #question_mark)?) } else { ::failure::bail!("api function wrapper called with a non-object json value"); } diff --git a/proxmox-api-macro/tests/ext-schema.rs b/proxmox-api-macro/tests/ext-schema.rs index dfda9fcc..372b08dc 100644 --- a/proxmox-api-macro/tests/ext-schema.rs +++ b/proxmox-api-macro/tests/ext-schema.rs @@ -21,9 +21,8 @@ pub const NAME_SCHEMA: schema::Schema = schema::StringSchema::new("Archive name. } )] /// Get an archive. -pub fn get_archive(archive_name: String) -> Result<(), Error> { +pub fn get_archive(archive_name: String) { let _ = archive_name; - Ok(()) } #[api(