api-macro: allow methods without return types

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-12-04 14:27:57 +01:00
parent c282c8ce23
commit b81beb4dfb
2 changed files with 8 additions and 3 deletions

View File

@ -405,6 +405,12 @@ fn create_wrapper_function(
// build the wrapping function: // build the wrapping function:
let func_name = &func.sig.ident; let func_name = &func.sig.ident;
let question_mark = match func.sig.output {
syn::ReturnType::Default => None,
_ => Some(quote!(?)),
};
wrapper_ts.extend(quote! { wrapper_ts.extend(quote! {
fn #api_func_name( fn #api_func_name(
mut input_params: ::serde_json::Value, mut input_params: ::serde_json::Value,
@ -413,7 +419,7 @@ fn create_wrapper_function(
) -> Result<::serde_json::Value, ::failure::Error> { ) -> Result<::serde_json::Value, ::failure::Error> {
if let ::serde_json::Value::Object(ref mut input_map) = &mut input_params { if let ::serde_json::Value::Object(ref mut input_map) = &mut input_params {
#body #body
Ok(::serde_json::to_value(#func_name(#args)?)?) Ok(::serde_json::to_value(#func_name(#args) #question_mark)?)
} else { } else {
::failure::bail!("api function wrapper called with a non-object json value"); ::failure::bail!("api function wrapper called with a non-object json value");
} }

View File

@ -21,9 +21,8 @@ pub const NAME_SCHEMA: schema::Schema = schema::StringSchema::new("Archive name.
} }
)] )]
/// Get an archive. /// Get an archive.
pub fn get_archive(archive_name: String) -> Result<(), Error> { pub fn get_archive(archive_name: String) {
let _ = archive_name; let _ = archive_name;
Ok(())
} }
#[api( #[api(