//! Modules and services can be generic. Based off of issue #2: //! https://github.com/AzureMarker/shaku/issues/2 use shaku::{module, Component, HasProvider, Interface, Provider}; use std::fmt::Debug; use std::sync::Arc; trait RegisterService: Debug + Interface {} trait RegisterProvider: Debug {} #[derive(Component, Debug)] #[shaku(interface = RegisterService)] struct RegisterServiceImpl { #[shaku(default)] #[allow(dead_code)] executor: E, } impl RegisterService for RegisterServiceImpl {} #[derive(Provider, Debug)] #[shaku(interface = RegisterProvider)] struct RegisterProviderImpl { #[shaku(inject)] #[allow(dead_code)] register_service: Arc>, } impl RegisterProvider for RegisterProviderImpl {} module! { MyModule { components = [RegisterServiceImpl], providers = [RegisterProviderImpl] } } #[test] fn can_use_generic_service_impl() { let module = MyModule::<()>::builder().build(); let register_service: Box = module.provide().unwrap(); assert_eq!( format!("{:?}", register_service), "RegisterProviderImpl { register_service: RegisterServiceImpl { executor: () } }" ); }