tailwag_macro_logic 0.2.1

The logic for A collection of macros to support the tailwag crate
Documentation
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Data, DeriveInput};

pub fn derive_struct(input: &DeriveInput) -> TokenStream {
    let &DeriveInput {
        ident,
        data,
        ..
    } = &input;

    // Panic with error message if we get a non-struct
    let Data::Struct(data) = data else { panic!("Only Structs are supported") };

    match &data.fields {
        syn::Fields::Named(fields) => {
            let _field_names = fields.named.iter().map(|f| &f.ident);

            let functions: Vec<TokenStream> = vec![
                // todo!("Add functions here")
            ];

            // TODO: Think about how to handle Generics, when they end up being needed.
            let parse_args_impl_tokens = quote!(
                impl tailwag::web_service::traits::BuildRoutes for #ident {
                    #(#functions)*
                }
            );

            parse_args_impl_tokens.into()
        },
        syn::Fields::Unnamed(_) => unimplemented!("Unnamed fields not supported yet"),
        syn::Fields::Unit => unimplemented!("Unit fields not supported yet"),
    }
}