diff --git a/proxmox-api-macro/src/api.rs b/proxmox-api-macro/src/api.rs index ce855fb0..75bd0c58 100644 --- a/proxmox-api-macro/src/api.rs +++ b/proxmox-api-macro/src/api.rs @@ -14,7 +14,7 @@ mod enums; mod method; mod structs; -pub const INTNAMES: &[&'static str] = &[ +pub const INTNAMES: &[&str] = &[ "Integer", "i8", "i16", "i32", "i64", "isize", "u8", "u16", "u32", "u64", "usize", ]; @@ -103,7 +103,7 @@ impl Schema { self.item.to_schema( ts, self.description.as_ref(), - &self.span, + self.span, &self.properties, true, ) @@ -113,7 +113,7 @@ impl Schema { self.item.to_schema( ts, self.description.as_ref(), - &self.span, + self.span, &self.properties, false, ) @@ -212,10 +212,10 @@ impl SchemaItem { &self, ts: &mut TokenStream, description: Option<&syn::LitStr>, - span: &Span, + span: Span, properties: &[(Ident, syn::Expr)], ) -> Result { - let description = description.ok_or_else(|| format_err!(*span, "missing description")); + let description = description.ok_or_else(|| format_err!(span, "missing description")); match self { SchemaItem::Null => { @@ -276,7 +276,7 @@ impl SchemaItem { &self, ts: &mut TokenStream, description: Option<&syn::LitStr>, - span: &Span, + span: Span, properties: &[(Ident, syn::Expr)], typed: bool, ) -> Result<(), Error> { diff --git a/proxmox-api-macro/src/api/enums.rs b/proxmox-api-macro/src/api/enums.rs index 4ffb7a9a..9ac64d6e 100644 --- a/proxmox-api-macro/src/api/enums.rs +++ b/proxmox-api-macro/src/api/enums.rs @@ -73,17 +73,14 @@ pub fn handle_enum( let args: AttrArgs = syn::parse2(attrib.tokens.clone())?; for arg in args.args { - match arg { - syn::NestedMeta::Meta(syn::Meta::NameValue(var)) => { - if var.path.is_ident("rename") { - match var.lit { - syn::Lit::Str(lit) => variants.push(lit), - _ => bail!(var.lit => "'rename' value must be a string literal"), - } - renamed = true; + if let syn::NestedMeta::Meta(syn::Meta::NameValue(var)) = arg { + if var.path.is_ident("rename") { + match var.lit { + syn::Lit::Str(lit) => variants.push(lit), + _ => bail!(var.lit => "'rename' value must be a string literal"), } + renamed = true; } - _ => (), // ignore } } } diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs index 6cb32ed7..d86b7bba 100644 --- a/proxmox-api-macro/src/api/method.rs +++ b/proxmox-api-macro/src/api/method.rs @@ -62,13 +62,10 @@ pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result { - let mut inner = TokenStream::new(); - schema.to_schema(&mut inner)?; - ts.extend(quote! { .returns(#inner) }); - } - None => (), + if let Some(schema) = returns_schema { + let mut inner = TokenStream::new(); + schema.to_schema(&mut inner)?; + ts.extend(quote! { .returns(#inner) }); } ts }; @@ -247,12 +244,10 @@ fn handle_function_signature( let param_type = if let Some((name, optional, schema)) = input_schema.find_obj_property_by_ident(&pat.ident.to_string()) { - match schema { - PropertySchema::Schema(schema) => match &schema.item { - SchemaItem::Inferred(span) => bail!(*span, "failed to infer type"), - _ => (), - }, - _ => (), + if let PropertySchema::Schema(schema) = schema { + if let SchemaItem::Inferred(span) = &schema.item { + bail!(*span, "failed to infer type"); + } } param_name = name.clone(); // Found an explicit parameter: extract it: @@ -426,5 +421,5 @@ fn create_wrapper_function( } }); - return Ok(api_func_name); + Ok(api_func_name) } diff --git a/proxmox-api-macro/src/util.rs b/proxmox-api-macro/src/util.rs index d00d8d01..8d1579fe 100644 --- a/proxmox-api-macro/src/util.rs +++ b/proxmox-api-macro/src/util.rs @@ -116,6 +116,8 @@ impl Parse for FieldName { /// Most of our schema definition consists of a json-like notation. /// For parsing we mostly just need to destinguish between objects and non-objects. /// For specific expression types we match on the contained expression later on. +// FIXME: Expr(Box) +#[allow(clippy::large_enum_variant)] pub enum JSONValue { Object(JSONObject), Expr(syn::Expr), @@ -283,7 +285,7 @@ impl JSONObject { input.parse_terminated(JSONMapEntry::parse)?; let mut elems = HashMap::with_capacity(map_elems.len()); for c in map_elems { - if elems.insert(c.key.clone().into(), c.value).is_some() { + if elems.insert(c.key.clone(), c.value).is_some() { bail!(c.key.span(), "duplicate '{}' in schema", c.key.as_str()); } }