@@ -51,7 +51,7 @@ const NEITHER_SUB_OR_UNSUB_ERR: &str = "pubsub attribute not annotated with eith
5151
5252impl RpcMethodAttribute {
5353 pub fn parse_attr ( method : & syn:: TraitItemMethod ) -> Result < Option < RpcMethodAttribute > > {
54- let output = & method. sig . decl . output ;
54+ let output = & method. sig . output ;
5555 let attrs = method
5656 . attrs
5757 . iter ( )
@@ -68,9 +68,9 @@ impl RpcMethodAttribute {
6868 fn parse_meta ( attr : & syn:: Attribute , output : & syn:: ReturnType ) -> Option < Result < RpcMethodAttribute > > {
6969 match attr. parse_meta ( ) . and_then ( validate_attribute_meta) {
7070 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) ) ,
7474 _ => None ,
7575 } ;
7676 attr_kind. map ( |kind| {
@@ -162,24 +162,27 @@ fn validate_attribute_meta(meta: syn::Meta) -> Result<syn::Meta> {
162162 }
163163 impl < ' a > Visit < ' a > for Visitor {
164164 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+ }
169171 }
170172 }
171173 }
172174
173175 let mut visitor = Visitor :: default ( ) ;
174176 visit:: visit_meta ( & mut visitor, & meta) ;
175177
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 ) => {
178181 validate_idents ( & meta, & visitor. meta_words , & [ METADATA_META_WORD , RAW_PARAMS_META_WORD ] ) ?;
179182 validate_idents ( & meta, & visitor. name_value_names , & [ RPC_NAME_KEY , RETURNS_META_WORD ] ) ?;
180183 validate_idents ( & meta, & visitor. meta_list_names , & [ ALIASES_KEY ] )
181184 }
182- PUB_SUB_ATTR_NAME => {
185+ Some ( PUB_SUB_ATTR_NAME ) => {
183186 validate_idents (
184187 & meta,
185188 & visitor. meta_words ,
@@ -223,7 +226,7 @@ fn get_meta_list(meta: &syn::Meta) -> Option<&syn::MetaList> {
223226fn get_name_value ( key : & str , ml : & syn:: MetaList ) -> Option < String > {
224227 ml. nested . iter ( ) . find_map ( |nested| {
225228 if let syn:: NestedMeta :: Meta ( syn:: Meta :: NameValue ( mnv) ) = nested {
226- if mnv. ident == key {
229+ if path_eq_str ( & mnv. path , key) {
227230 if let syn:: Lit :: Str ( ref lit) = mnv. lit {
228231 Some ( lit. value ( ) )
229232 } else {
@@ -240,8 +243,8 @@ fn get_name_value(key: &str, ml: &syn::MetaList) -> Option<String> {
240243
241244fn has_meta_word ( word : & str , ml : & syn:: MetaList ) -> bool {
242245 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)
245248 } else {
246249 false
247250 }
@@ -253,7 +256,7 @@ fn get_aliases(ml: &syn::MetaList) -> Vec<String> {
253256 . iter ( )
254257 . find_map ( |nested| {
255258 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 ) {
257260 Some ( list)
258261 } else {
259262 None
@@ -266,7 +269,7 @@ fn get_aliases(ml: &syn::MetaList) -> Vec<String> {
266269 list. nested
267270 . iter ( )
268271 . 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 {
270273 Some ( alias. value ( ) )
271274 } else {
272275 None
@@ -275,3 +278,11 @@ fn get_aliases(ml: &syn::MetaList) -> Vec<String> {
275278 . collect ( )
276279 } )
277280}
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