diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 68 |
1 files changed, 34 insertions, 34 deletions
@@ -71,6 +71,40 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { let mut type_converter = TypeConverter::default(); + let mut blanket_impl_attrs = Vec::new(); + let mut dyn_trait_attrs = Vec::new(); + + // FUTURE: use Vec::drain_filter once it's stable + let mut i = 0; + while i < original_trait.attrs.len() { + if original_trait.attrs[i].path.is_ident("blanket_impl_attr") { + let attr = original_trait.attrs.remove(i); + let group: Group = match syn::parse2(attr.tokens) { + Ok(g) => g, + Err(err) => { + return abort!( + err.span(), + "expected parenthesis: #[blanket_impl_attr(...)]" + ) + } + }; + let tokens = group.stream(); + blanket_impl_attrs.push(quote! {#[#tokens]}); + } else if original_trait.attrs[i].path.is_ident("dyn_trait_attr") { + let attr = original_trait.attrs.remove(i); + let group: Group = match syn::parse2(attr.tokens) { + Ok(g) => g, + Err(err) => { + return abort!(err.span(), "expected parenthesis: #[dyn_trait_attr(...)]") + } + }; + let tokens = group.stream(); + dyn_trait_attrs.push(quote! {#[#tokens]}); + } else { + i += 1; + } + } + for item in &original_trait.items { if let TraitItem::Type(assoc_type) = item { match parse_assoc_type(assoc_type) { @@ -146,40 +180,6 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { let mut method_impls: Vec<ImplItemMethod> = Vec::new(); - let mut blanket_impl_attrs = Vec::new(); - let mut dyn_trait_attrs = Vec::new(); - - // FUTURE: use Vec::drain_filter once it's stable - let mut i = 0; - while i < original_trait.attrs.len() { - if original_trait.attrs[i].path.is_ident("blanket_impl_attr") { - let attr = original_trait.attrs.remove(i); - let group: Group = match syn::parse2(attr.tokens) { - Ok(g) => g, - Err(err) => { - return abort!( - err.span(), - "expected parenthesis: #[blanket_impl_attr(...)]" - ) - } - }; - let tokens = group.stream(); - blanket_impl_attrs.push(quote! {#[#tokens]}); - } else if original_trait.attrs[i].path.is_ident("dyn_trait_attr") { - let attr = original_trait.attrs.remove(i); - let group: Group = match syn::parse2(attr.tokens) { - Ok(g) => g, - Err(err) => { - return abort!(err.span(), "expected parenthesis: #[dyn_trait_attr(...)]") - } - }; - let tokens = group.stream(); - dyn_trait_attrs.push(quote! {#[#tokens]}); - } else { - i += 1; - } - } - let mut dyn_trait = ItemTrait { ident: format_ident!("Dyn{}", original_trait.ident), |