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:
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");
}

View File

@ -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(