From 3add1337f63f7ceaa112422ade840c9b9056ff92 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 21 Jan 2019 07:47:17 -0500 Subject: [PATCH] create struct and fields --- .../salsa-macros/src/database_storage.rs | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/components/salsa-macros/src/database_storage.rs b/components/salsa-macros/src/database_storage.rs index 7957f645..87d54e8f 100644 --- a/components/salsa-macros/src/database_storage.rs +++ b/components/salsa-macros/src/database_storage.rs @@ -20,9 +20,40 @@ use syn::{Ident, Path, Token}; /// /// impl Database { pub(crate) fn database_storage(input: TokenStream) -> TokenStream { - let _input: DatabaseStorage = syn::parse_macro_input!(input as DatabaseStorage); + let DatabaseStorage { + storage_struct_name, + database_name, + query_groups, + } = syn::parse_macro_input!(input as DatabaseStorage); - unimplemented!() + // For each query `fn foo() for FooType` create + // + // ``` + // foo: >::Storage, + // ``` + let mut fields = proc_macro2::TokenStream::new(); + for query_group in &query_groups { + for Query { + query_name, + query_type, + } in &query_group.queries + { + fields.extend(quote! { + #query_name: <#query_type as ::salsa::Query<#database_name>>::Storage, + }); + } + } + + let output = quote! { + #[derive(Default)] + // XXX attributes + // XXX visibility + struct #storage_struct_name { + #fields + } + }; + + output.into() } struct DatabaseStorage {