|
1 | | -use proc_macro2::{Group, Span, TokenStream, TokenTree}; |
2 | | -use quote::{ToTokens, format_ident, quote}; |
| 1 | +use proc_macro2::{Span, TokenStream}; |
| 2 | +use quote::{ToTokens, quote}; |
3 | 3 | use syn::parse::discouraged::Speculative; |
4 | 4 | use syn::parse::{Parse, ParseStream}; |
5 | 5 | use syn::spanned::Spanned; |
6 | 6 | use syn::token::{Colon, For}; |
7 | 7 | use syn::{Error, FnArg, Ident, ImplItem, ItemImpl, Type, parse2}; |
8 | 8 |
|
9 | | -use crate::derive_component::{replace_self_receiver, replace_self_type, to_snake_case_ident}; |
10 | 9 | use crate::derive_provider::{ |
11 | 10 | derive_component_name_from_provider_impl, derive_is_provider_for, derive_provider_struct, |
12 | 11 | }; |
13 | 12 | use crate::parse::SimpleType; |
| 13 | +use crate::replace_self::{ |
| 14 | + replace_self_receiver, replace_self_type, replace_self_var, to_snake_case_ident, |
| 15 | +}; |
14 | 16 |
|
15 | 17 | pub fn cgp_impl(attr: TokenStream, body: TokenStream) -> syn::Result<TokenStream> { |
16 | 18 | let spec: ImplProviderSpec = parse2(attr)?; |
@@ -153,35 +155,3 @@ pub fn transform_impl_trait( |
153 | 155 |
|
154 | 156 | Ok(out_impl) |
155 | 157 | } |
156 | | - |
157 | | -fn replace_self_var(stream: TokenStream, replaced_ident: &Ident) -> TokenStream { |
158 | | - let self_ident = format_ident!("self"); |
159 | | - |
160 | | - let mut result_stream: Vec<TokenTree> = Vec::new(); |
161 | | - |
162 | | - let token_iter = stream.into_iter(); |
163 | | - |
164 | | - for tree in token_iter { |
165 | | - match tree { |
166 | | - TokenTree::Ident(ident) => { |
167 | | - if ident == self_ident { |
168 | | - result_stream.push(TokenTree::Ident(replaced_ident.clone())); |
169 | | - } else { |
170 | | - result_stream.push(TokenTree::Ident(ident)); |
171 | | - } |
172 | | - } |
173 | | - TokenTree::Group(group) => { |
174 | | - let replaced_stream = replace_self_var(group.stream(), replaced_ident); |
175 | | - let replaced_group = Group::new(group.delimiter(), replaced_stream); |
176 | | - |
177 | | - result_stream.push(TokenTree::Group(replaced_group)); |
178 | | - } |
179 | | - TokenTree::Punct(punct) => { |
180 | | - result_stream.push(TokenTree::Punct(punct)); |
181 | | - } |
182 | | - TokenTree::Literal(lit) => result_stream.push(TokenTree::Literal(lit)), |
183 | | - } |
184 | | - } |
185 | | - |
186 | | - result_stream.into_iter().collect() |
187 | | -} |
0 commit comments