diff options
author | HampusM <hampus@hampusmat.com> | 2022-07-24 15:58:30 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-07-24 15:58:30 +0200 |
commit | 5335cdad99a6d566ea6e83f97012c7954ba93c45 (patch) | |
tree | b4c91634b34f6d3858d6dd210afb609d9a1f76d7 /macros/src/injectable_impl.rs | |
parent | 5ea16d1e5bf716831bc8c54c5c4c86229d7e0463 (diff) |
feat: add support for generics
Diffstat (limited to 'macros/src/injectable_impl.rs')
-rw-r--r-- | macros/src/injectable_impl.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/macros/src/injectable_impl.rs b/macros/src/injectable_impl.rs index 8bb6c7a..822a432 100644 --- a/macros/src/injectable_impl.rs +++ b/macros/src/injectable_impl.rs @@ -1,5 +1,6 @@ use quote::{quote, ToTokens}; use syn::parse::{Parse, ParseStream}; +use syn::Generics; use syn::{ parse_str, punctuated::Punctuated, token::Comma, ExprMethodCall, FnArg, GenericArgument, Ident, ImplItem, ImplItemMethod, ItemImpl, Path, PathArguments, @@ -12,6 +13,7 @@ pub struct InjectableImpl { pub dependency_types: Vec<Type>, pub self_type: Type, + pub generics: Generics, pub original_impl: ItemImpl, } @@ -25,6 +27,7 @@ impl Parse for InjectableImpl Ok(dependency_types) => Ok(Self { dependency_types, self_type: impl_parsed_input.self_ty.as_ref().clone(), + generics: impl_parsed_input.generics.clone(), original_impl: impl_parsed_input, }), Err(error_msg) => Err(input.error(error_msg)), @@ -39,17 +42,21 @@ impl InjectableImpl { pub fn expand(&self) -> proc_macro2::TokenStream { - let original_impl = &self.original_impl; - let self_type = &self.self_type; + let Self { + dependency_types, + self_type, + generics, + original_impl, + } = self; let di_container_var: Ident = parse_str(DI_CONTAINER_VAR_NAME).unwrap(); - let get_dependencies = Self::_create_get_dependencies(&self.dependency_types); + let get_dependencies = Self::_create_get_dependencies(dependency_types); quote! { #original_impl - impl syrette::interfaces::injectable::Injectable for #self_type { + impl #generics syrette::interfaces::injectable::Injectable for #self_type { fn resolve( #di_container_var: &syrette::DIContainer ) -> syrette::libs::error_stack::Result< |