@@ -3,7 +3,7 @@ use proc_macro2::{Ident, Span};
3
3
use quote:: { quote, ToTokens } ;
4
4
use syn:: {
5
5
parse:: { Parse , ParseStream } ,
6
- parse_macro_input , parse_quote,
6
+ parse_quote,
7
7
punctuated:: Punctuated ,
8
8
Attribute , Data , DataStruct , DeriveInput , Field , Fields , GenericArgument , GenericParam ,
9
9
ImplGenerics , Lifetime , LifetimeDef , Path , PathArguments , ReturnType , Token , Type ,
@@ -18,25 +18,23 @@ struct FetchStructAttributes {
18
18
pub read_only_derive_args : Punctuated < syn:: NestedMeta , syn:: token:: Comma > ,
19
19
}
20
20
21
+ pub static FILTER_ATTRIBUTE_NAME : & str = "filter" ;
21
22
static MUTABLE_ATTRIBUTE_NAME : & str = "mutable" ;
22
23
static READ_ONLY_DERIVE_ATTRIBUTE_NAME : & str = "read_only_derive" ;
23
24
24
25
mod field_attr_keywords {
25
26
syn:: custom_keyword!( ignore) ;
26
27
}
27
28
28
- static FETCH_ATTRIBUTE_NAME : & str = "fetch" ;
29
- static FILTER_FETCH_ATTRIBUTE_NAME : & str = "filter_fetch" ;
30
-
31
- pub fn derive_fetch_impl ( input : TokenStream ) -> TokenStream {
32
- let ast = parse_macro_input ! ( input as DeriveInput ) ;
29
+ pub static WORLD_QUERY_ATTRIBUTE_NAME : & str = "world_query" ;
33
30
31
+ pub fn derive_world_query_impl ( ast : DeriveInput ) -> TokenStream {
34
32
let mut fetch_struct_attributes = FetchStructAttributes :: default ( ) ;
35
33
for attr in & ast. attrs {
36
34
if !attr
37
35
. path
38
36
. get_ident ( )
39
- . map_or ( false , |ident| ident == FETCH_ATTRIBUTE_NAME )
37
+ . map_or ( false , |ident| ident == WORLD_QUERY_ATTRIBUTE_NAME )
40
38
{
41
39
continue ;
42
40
}
@@ -74,7 +72,7 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
74
72
}
75
73
Ok ( ( ) )
76
74
} )
77
- . unwrap_or_else ( |_| panic ! ( "Invalid `{}` attribute format" , FETCH_ATTRIBUTE_NAME ) ) ;
75
+ . unwrap_or_else ( |_| panic ! ( "Invalid `{}` attribute format" , WORLD_QUERY_ATTRIBUTE_NAME ) ) ;
78
76
}
79
77
80
78
let FetchImplTokens {
@@ -101,7 +99,11 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
101
99
field_types : _,
102
100
query_types,
103
101
fetch_init_types,
104
- } = fetch_impl_tokens ( & ast, FETCH_ATTRIBUTE_NAME , fetch_struct_attributes. mutable ) ;
102
+ } = fetch_impl_tokens (
103
+ & ast,
104
+ WORLD_QUERY_ATTRIBUTE_NAME ,
105
+ fetch_struct_attributes. mutable ,
106
+ ) ;
105
107
106
108
if !has_world_lifetime {
107
109
panic ! ( "Expected a struct with a lifetime" ) ;
@@ -319,9 +321,7 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
319
321
tokens
320
322
}
321
323
322
- pub fn derive_filter_fetch_impl ( input : TokenStream ) -> TokenStream {
323
- let ast = parse_macro_input ! ( input as DeriveInput ) ;
324
-
324
+ pub fn derive_world_query_filter_impl ( ast : DeriveInput ) -> TokenStream {
325
325
let FetchImplTokens {
326
326
struct_name,
327
327
struct_name_read_only : _,
@@ -346,7 +346,7 @@ pub fn derive_filter_fetch_impl(input: TokenStream) -> TokenStream {
346
346
field_types,
347
347
query_types : _,
348
348
fetch_init_types : _,
349
- } = fetch_impl_tokens ( & ast, FILTER_FETCH_ATTRIBUTE_NAME , false ) ;
349
+ } = fetch_impl_tokens ( & ast, WORLD_QUERY_ATTRIBUTE_NAME , false ) ;
350
350
351
351
if has_world_lifetime {
352
352
panic ! ( "Expected a struct without a lifetime" ) ;
0 commit comments