|
1 | 1 | //! Trait parsing and client and server generation.
|
2 | 2 |
|
3 |
| -use proc_macro2::{Span, TokenStream}; |
| 3 | +use proc_macro2::TokenStream; |
4 | 4 | use quote::{format_ident, quote, TokenStreamExt};
|
5 | 5 | use syn::{
|
6 | 6 | braced,
|
| 7 | + meta::ParseNestedMeta, |
7 | 8 | parse::{Parse, ParseStream},
|
8 |
| - Attribute, AttributeArgs, Error, GenericParam, Generics, Ident, Lifetime, LifetimeDef, Meta, NestedMeta, |
9 |
| - Token, TypeParam, Visibility, WhereClause, |
| 9 | + Attribute, GenericParam, Generics, Ident, Lifetime, LifetimeParam, Token, TypeParam, Visibility, WhereClause, |
10 | 10 | };
|
11 | 11 |
|
12 | 12 | use crate::{
|
@@ -70,28 +70,17 @@ impl Parse for TraitDef {
|
70 | 70 | }
|
71 | 71 |
|
72 | 72 | impl TraitDef {
|
73 |
| - /// Applies attributes specified by the procedural macro invocation. |
74 |
| - pub fn apply_attrs(&mut self, attrs: AttributeArgs) -> syn::Result<()> { |
75 |
| - for attr in attrs { |
76 |
| - if let NestedMeta::Meta(Meta::Path(path)) = attr { |
77 |
| - if path.is_ident("clone") { |
78 |
| - if self.is_taking_value() { |
79 |
| - return Err(Error::new( |
80 |
| - Span::call_site(), |
81 |
| - "the client cannot be clonable if a method takes self by value", |
82 |
| - )); |
83 |
| - } |
84 |
| - self.clone = true; |
85 |
| - } else { |
86 |
| - return Err(Error::new( |
87 |
| - Span::call_site(), |
88 |
| - format!("unknown attribute: {}", path.get_ident().unwrap()), |
89 |
| - )); |
90 |
| - } |
| 73 | + /// Parses and applies attributes specified by the procedural macro invocation. |
| 74 | + pub fn parse_meta(&mut self, meta: ParseNestedMeta) -> syn::Result<()> { |
| 75 | + if meta.path.is_ident("clone") { |
| 76 | + if self.is_taking_value() { |
| 77 | + return Err(meta.error("the client cannot be clonable if a method takes self by value")); |
91 | 78 | }
|
| 79 | + self.clone = true; |
| 80 | + Ok(()) |
| 81 | + } else { |
| 82 | + Err(meta.error("unknown attribute")) |
92 | 83 | }
|
93 |
| - |
94 |
| - Ok(()) |
95 | 84 | }
|
96 | 85 |
|
97 | 86 | /// True, if any trait method takes self by value.
|
@@ -167,7 +156,7 @@ impl TraitDef {
|
167 | 156 |
|
168 | 157 | if with_lifetime {
|
169 | 158 | let target_lt: Lifetime = syn::parse2(quote! {'target}).unwrap();
|
170 |
| - ty_generics.params.insert(0, LifetimeDef::new(target_lt).into()); |
| 159 | + ty_generics.params.insert(0, LifetimeParam::new(target_lt).into()); |
171 | 160 | }
|
172 | 161 |
|
173 | 162 | let mut impl_generics = ty_generics.clone();
|
|
0 commit comments