@@ -26,9 +26,9 @@ pub enum Attribute {
26
26
Sql ( ToSqlConfig ) ,
27
27
}
28
28
29
- impl ToTokens for Attribute {
30
- fn to_tokens ( & self , tokens : & mut TokenStream2 ) {
31
- let quoted = match self {
29
+ impl Attribute {
30
+ pub ( crate ) fn to_sql_entity_graph_tokens ( & self ) -> TokenStream2 {
31
+ match self {
32
32
Attribute :: Immutable => quote ! { pgx:: datum:: sql_entity_graph:: ExternArgs :: Immutable } ,
33
33
Attribute :: Strict => quote ! { pgx:: datum:: sql_entity_graph:: ExternArgs :: Strict } ,
34
34
Attribute :: Stable => quote ! { pgx:: datum:: sql_entity_graph:: ExternArgs :: Stable } ,
@@ -65,7 +65,52 @@ impl ToTokens for Attribute {
65
65
}
66
66
// This attribute is handled separately
67
67
Attribute :: Sql ( _) => {
68
- return ;
68
+ quote ! { }
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ impl ToTokens for Attribute {
75
+ fn to_tokens ( & self , tokens : & mut TokenStream2 ) {
76
+ let quoted = match self {
77
+ Attribute :: Immutable => quote ! { immutable } ,
78
+ Attribute :: Strict => quote ! { strict } ,
79
+ Attribute :: Stable => quote ! { stable } ,
80
+ Attribute :: Volatile => quote ! { volatile } ,
81
+ Attribute :: Raw => quote ! { raw } ,
82
+ Attribute :: NoGuard => quote ! { no_guard } ,
83
+ Attribute :: ParallelSafe => {
84
+ quote ! { parallel_safe }
85
+ }
86
+ Attribute :: ParallelUnsafe => {
87
+ quote ! { parallel_unsafe }
88
+ }
89
+ Attribute :: ParallelRestricted => {
90
+ quote ! { parallel_restricted }
91
+ }
92
+ Attribute :: Error ( s) => {
93
+ quote ! { error = #s }
94
+ }
95
+ Attribute :: Schema ( s) => {
96
+ quote ! { schema = #s }
97
+ }
98
+ Attribute :: Name ( s) => {
99
+ quote ! { name = #s }
100
+ }
101
+ Attribute :: Cost ( s) => {
102
+ quote ! { cost = #s }
103
+ }
104
+ Attribute :: Requires ( items) => {
105
+ let items_iter = items
106
+ . iter ( )
107
+ . map ( |x| x. to_token_stream ( ) )
108
+ . collect :: < Vec < _ > > ( ) ;
109
+ quote ! { requires = [ #( #items_iter) , * ] }
110
+ }
111
+ // This attribute is handled separately
112
+ Attribute :: Sql ( to_sql_config) => {
113
+ quote ! { sql = #to_sql_config }
69
114
}
70
115
} ;
71
116
tokens. append_all ( quoted) ;
@@ -128,7 +173,7 @@ impl Parse for Attribute {
128
173
}
129
174
}
130
175
}
131
- _ => return Err ( syn:: Error :: new ( Span :: call_site ( ) , "Invalid option" ) ) ,
176
+ e => return Err ( syn:: Error :: new ( Span :: call_site ( ) , format ! ( "Invalid option `{}` inside `{} {}`" , e , ident . to_string ( ) , input . to_string ( ) ) ) ) ,
132
177
} ;
133
178
Ok ( found)
134
179
}
0 commit comments