diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-21 19:52:30 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-21 19:54:46 +0100 |
commit | 0dd8413eca378e5dc2e6cbdc6f9c6f8bde604e4a (patch) | |
tree | e191baf60e478ed040c6a865cb7676f3465860b4 /src/parse_assoc_type.rs | |
parent | 23fcd4ef079ad2b4aed69b4f363cbb9e7102c4ed (diff) |
support boxed Iterator in Option
Diffstat (limited to 'src/parse_assoc_type.rs')
-rw-r--r-- | src/parse_assoc_type.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/parse_assoc_type.rs b/src/parse_assoc_type.rs index 85f3723..048e58c 100644 --- a/src/parse_assoc_type.rs +++ b/src/parse_assoc_type.rs @@ -1,7 +1,7 @@ -use proc_macro2::Span; +use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; use syn::spanned::Spanned; -use syn::{GenericArgument, Ident, Path, PathArguments, PathSegment, TraitItemType, Type}; +use syn::{GenericArgument, Ident, PathArguments, PathSegment, TraitItemType, Type}; use crate::match_assoc_type; use crate::parse_trait_sig::TypeTransform; @@ -16,16 +16,16 @@ pub enum AssocTypeParseError { #[derive(Debug, Clone)] pub struct BoxType { - trait_name: Path, - placeholder_lifetime: bool, + pub inner: TokenStream, + pub placeholder_lifetime: bool, } impl ToTokens for BoxType { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - let path = &self.trait_name; + let inner = &self.inner; match self.placeholder_lifetime { - true => tokens.extend(quote! {Box<dyn #path + '_>}), - false => tokens.extend(quote! {Box<dyn #path>}), + true => tokens.extend(quote! {Box<#inner + '_>}), + false => tokens.extend(quote! {Box<#inner>}), } } } @@ -79,10 +79,11 @@ pub fn parse_assoc_type( } } } + let path = &bound.path; return Ok(( &assoc_type.ident, DestType::Box(BoxType { - trait_name: bound.path.clone(), + inner: quote! {dyn #path}, placeholder_lifetime: !lifetime_bounds(&assoc_type.bounds) .any(|l| l.ident == "static"), }), |