diff --git a/proxmox-api-macro/src/api/structs.rs b/proxmox-api-macro/src/api/structs.rs index 97b128c2..e424e8c9 100644 --- a/proxmox-api-macro/src/api/structs.rs +++ b/proxmox-api-macro/src/api/structs.rs @@ -2,13 +2,13 @@ use std::convert::TryInto; use failure::Error; -use proc_macro2::TokenStream; +use proc_macro2::{Ident, TokenStream}; use quote::quote_spanned; use super::Schema; use crate::util::{self, JSONObject}; -pub fn handle_struct(attribs: JSONObject, stru: syn::ItemStruct) -> Result { +pub fn handle_struct(attribs: JSONObject, mut stru: syn::ItemStruct) -> Result { let mut schema: Schema = attribs.try_into()?; if schema.description.is_none() { @@ -16,14 +16,31 @@ pub fn handle_struct(attribs: JSONObject, stru: syn::ItemStruct) -> Result finish_schema(schema, &stru, &stru.ident), + syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => { + handle_newtype_struct(schema, &mut stru) + } + syn::Fields::Unnamed(fields) => bail!( + fields.paren_token.span, + "api macro does not support tuple structs" + ), + syn::Fields::Named(fields) => handle_regular_struct(schema, &mut stru), + } +} + +pub fn finish_schema( + schema: Schema, + stru: &syn::ItemStruct, + name: &Ident, +) -> Result { let schema = { let mut ts = TokenStream::new(); schema.to_schema(&mut ts)?; ts }; - let name = &stru.ident; - Ok(quote_spanned! { name.span() => #stru impl #name { @@ -31,3 +48,17 @@ pub fn handle_struct(attribs: JSONObject, stru: syn::ItemStruct) -> Result Result { + finish_schema(schema, &stru, &stru.ident) +} + +pub fn handle_regular_struct( + schema: Schema, + stru: &mut syn::ItemStruct, +) -> Result { + todo!(); +}