mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-23 13:42:04 +00:00
api-macro: match the item type early
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
1ae127b63a
commit
74ed56957d
@ -263,6 +263,10 @@ impl SchemaArray {
|
|||||||
/// See the top level macro documentation for a complete example.
|
/// See the top level macro documentation for a complete example.
|
||||||
pub(crate) fn api(attr: TokenStream, item: TokenStream) -> Result<TokenStream, Error> {
|
pub(crate) fn api(attr: TokenStream, item: TokenStream) -> Result<TokenStream, Error> {
|
||||||
let attribs = JSONObject::parse_inner.parse2(attr)?;
|
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"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,7 @@ use crate::util::{BareAssignment, JSONObject, SimpleIdent};
|
|||||||
/// with an `#[api]` attribute and produce a `const ApiMethod` named after the function.
|
/// with an `#[api]` attribute and produce a `const ApiMethod` named after the function.
|
||||||
///
|
///
|
||||||
/// See the top level macro documentation for a complete example.
|
/// See the top level macro documentation for a complete example.
|
||||||
pub fn handle_method(mut attribs: JSONObject, item: TokenStream) -> Result<TokenStream, Error> {
|
pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result<TokenStream, Error> {
|
||||||
let mut func: syn::ItemFn = syn::parse2(item)?;
|
|
||||||
|
|
||||||
let mut input_schema: Schema = attribs
|
let mut input_schema: Schema = attribs
|
||||||
.remove_required_element("input")?
|
.remove_required_element("input")?
|
||||||
.into_object("input schema definition")?
|
.into_object("input schema definition")?
|
||||||
|
Loading…
Reference in New Issue
Block a user