diff --git a/proxmox-api-macro/src/api.rs b/proxmox-api-macro/src/api.rs index b55a6b45..999fa494 100644 --- a/proxmox-api-macro/src/api.rs +++ b/proxmox-api-macro/src/api.rs @@ -263,6 +263,10 @@ impl SchemaArray { /// See the top level macro documentation for a complete example. pub(crate) fn api(attr: TokenStream, item: TokenStream) -> Result { let attribs = JSONObject::parse_inner.parse2(attr)?; + let item: syn::Item = syn::parse2(item)?; - method::handle_method(attribs, item) + match item { + syn::Item::Fn(func) => method::handle_method(attribs, func), + _ => bail!(item => "api macro only works on functions"), + } } diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs index cc793dbe..4efed1b7 100644 --- a/proxmox-api-macro/src/api/method.rs +++ b/proxmox-api-macro/src/api/method.rs @@ -15,9 +15,7 @@ use crate::util::{BareAssignment, JSONObject, SimpleIdent}; /// with an `#[api]` attribute and produce a `const ApiMethod` named after the function. /// /// See the top level macro documentation for a complete example. -pub fn handle_method(mut attribs: JSONObject, item: TokenStream) -> Result { - let mut func: syn::ItemFn = syn::parse2(item)?; - +pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result { let mut input_schema: Schema = attribs .remove_required_element("input")? .into_object("input schema definition")?