Skip to content

Commit

Permalink
Use ProviderFn in simple_no_macros example
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureMarker committed May 26, 2020
1 parent b961370 commit d01cbf9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions shaku/examples/simple_no_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use shaku::{
Component, HasComponent, HasProvider, Interface, Module, ModuleBuildContext, ModuleBuilder,
Provider,
Provider, ProviderFn,
};
use std::error::Error;
use std::fmt::Debug;
Expand Down Expand Up @@ -56,13 +56,15 @@ impl<M: Module + HasComponent<dyn SampleDependency>> Provider<M> for SampleServi

struct SampleModule {
sample_dependency: Arc<dyn SampleDependency>,
sample_service: Arc<ProviderFn<Self, dyn SampleService>>,
}
impl Module for SampleModule {
type Submodules = ();

fn build(context: &mut ModuleBuildContext<Self>) -> Self {
Self {
sample_dependency: Self::build_component(context),
sample_service: context.provider_fn::<SampleServiceImpl>(),
}
}
}
Expand All @@ -85,7 +87,7 @@ impl HasComponent<dyn SampleDependency> for SampleModule {
}
impl HasProvider<dyn SampleService> for SampleModule {
fn provide(&self) -> Result<Box<dyn SampleService>, Box<dyn Error>> {
SampleServiceImpl::provide(self)
(self.sample_service)(self)
}
}

Expand Down

0 comments on commit d01cbf9

Please sign in to comment.