mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-23 13:10:19 +00:00
use new
with index to create group storage
This commit is contained in:
parent
0da53151c5
commit
9bd9f8b202
2 changed files with 20 additions and 5 deletions
|
@ -46,12 +46,14 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
// For each query group `foo::MyGroup` create a link to its
|
||||
// `foo::MyGroupGroupStorage`
|
||||
let mut storage_fields = proc_macro2::TokenStream::new();
|
||||
let mut storage_initializers = proc_macro2::TokenStream::new();
|
||||
let mut has_group_impls = proc_macro2::TokenStream::new();
|
||||
for (((query_group, group_name_snake), group_storage), group_key) in query_groups
|
||||
for ((((query_group, group_name_snake), group_storage), group_key), group_index) in query_groups
|
||||
.iter()
|
||||
.zip(&query_group_names_snake)
|
||||
.zip(&query_group_storage_names)
|
||||
.zip(&query_group_key_names)
|
||||
.zip(0_usize..)
|
||||
{
|
||||
let group_path = &query_group.group_path;
|
||||
let group_name = query_group.name();
|
||||
|
@ -61,6 +63,13 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
storage_fields.extend(quote! {
|
||||
#group_name_snake: #group_storage,
|
||||
});
|
||||
|
||||
// rewrite the last identifier (`MyGroup`, above) to
|
||||
// (e.g.) `MyGroupGroupStorage`.
|
||||
storage_initializers.extend(quote! {
|
||||
#group_name_snake: #group_storage::new(#group_index),
|
||||
});
|
||||
|
||||
// ANCHOR:HasQueryGroup
|
||||
has_group_impls.extend(quote! {
|
||||
impl salsa::plumbing::HasQueryGroup<#group_path> for #database_name {
|
||||
|
@ -81,11 +90,18 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
|
||||
// create group storage wrapper struct
|
||||
output.extend(quote! {
|
||||
#[derive(Default)]
|
||||
#[doc(hidden)]
|
||||
#visibility struct __SalsaDatabaseStorage {
|
||||
#storage_fields
|
||||
}
|
||||
|
||||
impl Default for __SalsaDatabaseStorage {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
#storage_initializers
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// create query database_key wrapper struct
|
||||
|
|
|
@ -478,14 +478,13 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
|
|||
#storage_fields
|
||||
}
|
||||
|
||||
impl<DB__> Default for #group_storage<DB__>
|
||||
impl<DB__> #group_storage<DB__>
|
||||
where
|
||||
DB__: #trait_name + #requires,
|
||||
DB__: salsa::plumbing::HasQueryGroup<#group_struct>,
|
||||
DB__: salsa::Database,
|
||||
{
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
#trait_vis fn new(group_index: usize) -> Self {
|
||||
#group_storage {
|
||||
#storage_defaults
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue