@@ -51,7 +51,7 @@ const NEITHER_SUB_OR_UNSUB_ERR: &str = "pubsub attribute not annotated with eith
51
51
52
52
impl RpcMethodAttribute {
53
53
pub fn parse_attr ( method : & syn:: TraitItemMethod ) -> Result < Option < RpcMethodAttribute > > {
54
- let output = & method. sig . decl . output ;
54
+ let output = & method. sig . output ;
55
55
let attrs = method
56
56
. attrs
57
57
. iter ( )
@@ -68,9 +68,9 @@ impl RpcMethodAttribute {
68
68
fn parse_meta ( attr : & syn:: Attribute , output : & syn:: ReturnType ) -> Option < Result < RpcMethodAttribute > > {
69
69
match attr. parse_meta ( ) . and_then ( validate_attribute_meta) {
70
70
Ok ( ref meta) => {
71
- let attr_kind = match meta. name ( ) . to_string ( ) . as_ref ( ) {
72
- RPC_ATTR_NAME => Some ( Self :: parse_rpc ( meta, output) ) ,
73
- PUB_SUB_ATTR_NAME => Some ( Self :: parse_pubsub ( meta) ) ,
71
+ let attr_kind = match path_to_str ( meta. path ( ) ) . as_ref ( ) . map ( String :: as_str ) {
72
+ Some ( RPC_ATTR_NAME ) => Some ( Self :: parse_rpc ( meta, output) ) ,
73
+ Some ( PUB_SUB_ATTR_NAME ) => Some ( Self :: parse_pubsub ( meta) ) ,
74
74
_ => None ,
75
75
} ;
76
76
attr_kind. map ( |kind| {
@@ -162,24 +162,27 @@ fn validate_attribute_meta(meta: syn::Meta) -> Result<syn::Meta> {
162
162
}
163
163
impl < ' a > Visit < ' a > for Visitor {
164
164
fn visit_meta ( & mut self , meta : & syn:: Meta ) {
165
- match meta {
166
- syn:: Meta :: List ( list) => self . meta_list_names . push ( list. ident . to_string ( ) ) ,
167
- syn:: Meta :: Word ( ident) => self . meta_words . push ( ident. to_string ( ) ) ,
168
- syn:: Meta :: NameValue ( nv) => self . name_value_names . push ( nv. ident . to_string ( ) ) ,
165
+ if let Some ( ident) = path_to_str ( meta. path ( ) ) {
166
+ match meta {
167
+ syn:: Meta :: Path ( _) => self . meta_words . push ( ident) ,
168
+ syn:: Meta :: List ( _) => self . meta_list_names . push ( ident) ,
169
+ syn:: Meta :: NameValue ( _) => self . name_value_names . push ( ident) ,
170
+ }
169
171
}
170
172
}
171
173
}
172
174
173
175
let mut visitor = Visitor :: default ( ) ;
174
176
visit:: visit_meta ( & mut visitor, & meta) ;
175
177
176
- match meta. name ( ) . to_string ( ) . as_ref ( ) {
177
- RPC_ATTR_NAME => {
178
+ let ident = path_to_str ( meta. path ( ) ) ;
179
+ match ident. as_ref ( ) . map ( String :: as_str) {
180
+ Some ( RPC_ATTR_NAME ) => {
178
181
validate_idents ( & meta, & visitor. meta_words , & [ METADATA_META_WORD , RAW_PARAMS_META_WORD ] ) ?;
179
182
validate_idents ( & meta, & visitor. name_value_names , & [ RPC_NAME_KEY , RETURNS_META_WORD ] ) ?;
180
183
validate_idents ( & meta, & visitor. meta_list_names , & [ ALIASES_KEY ] )
181
184
}
182
- PUB_SUB_ATTR_NAME => {
185
+ Some ( PUB_SUB_ATTR_NAME ) => {
183
186
validate_idents (
184
187
& meta,
185
188
& visitor. meta_words ,
@@ -223,7 +226,7 @@ fn get_meta_list(meta: &syn::Meta) -> Option<&syn::MetaList> {
223
226
fn get_name_value ( key : & str , ml : & syn:: MetaList ) -> Option < String > {
224
227
ml. nested . iter ( ) . find_map ( |nested| {
225
228
if let syn:: NestedMeta :: Meta ( syn:: Meta :: NameValue ( mnv) ) = nested {
226
- if mnv. ident == key {
229
+ if path_eq_str ( & mnv. path , key) {
227
230
if let syn:: Lit :: Str ( ref lit) = mnv. lit {
228
231
Some ( lit. value ( ) )
229
232
} else {
@@ -240,8 +243,8 @@ fn get_name_value(key: &str, ml: &syn::MetaList) -> Option<String> {
240
243
241
244
fn has_meta_word ( word : & str , ml : & syn:: MetaList ) -> bool {
242
245
ml. nested . iter ( ) . any ( |nested| {
243
- if let syn:: NestedMeta :: Meta ( syn:: Meta :: Word ( w ) ) = nested {
244
- w == word
246
+ if let syn:: NestedMeta :: Meta ( syn:: Meta :: Path ( p ) ) = nested {
247
+ path_eq_str ( & p , word)
245
248
} else {
246
249
false
247
250
}
@@ -253,7 +256,7 @@ fn get_aliases(ml: &syn::MetaList) -> Vec<String> {
253
256
. iter ( )
254
257
. find_map ( |nested| {
255
258
if let syn:: NestedMeta :: Meta ( syn:: Meta :: List ( list) ) = nested {
256
- if list. ident == ALIASES_KEY {
259
+ if path_eq_str ( & list. path , ALIASES_KEY ) {
257
260
Some ( list)
258
261
} else {
259
262
None
@@ -266,7 +269,7 @@ fn get_aliases(ml: &syn::MetaList) -> Vec<String> {
266
269
list. nested
267
270
. iter ( )
268
271
. filter_map ( |nm| {
269
- if let syn:: NestedMeta :: Literal ( syn:: Lit :: Str ( alias) ) = nm {
272
+ if let syn:: NestedMeta :: Lit ( syn:: Lit :: Str ( alias) ) = nm {
270
273
Some ( alias. value ( ) )
271
274
} else {
272
275
None
@@ -275,3 +278,11 @@ fn get_aliases(ml: &syn::MetaList) -> Vec<String> {
275
278
. collect ( )
276
279
} )
277
280
}
281
+
282
+ fn path_eq_str ( path : & syn:: Path , s : & str ) -> bool {
283
+ path. get_ident ( ) . map_or ( false , |i| i == s)
284
+ }
285
+
286
+ fn path_to_str ( path : & syn:: Path ) -> Option < String > {
287
+ Some ( path. get_ident ( ) ?. to_string ( ) )
288
+ }
0 commit comments