From 2a44ec3ffdcd78b23ac31b722b4312774d643c3a Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 24 Sep 2022 16:14:45 +0200 Subject: refactor!: remove repetition of declaring factory interfaces BREAKING CHANGE: The to_default_factory method of the blocking and async DI containers now expect a function returning another function --- examples/async/bootstrap.rs | 6 ++++-- examples/with-3rd-party/bootstrap.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/async/bootstrap.rs b/examples/async/bootstrap.rs index 51af067..dd2febe 100644 --- a/examples/async/bootstrap.rs +++ b/examples/async/bootstrap.rs @@ -30,9 +30,11 @@ pub async fn bootstrap() -> Result> di_container .bind::() .to_default_factory(&|_| { - let cat: TransientPtr = TransientPtr::new(Cat::new()); + Box::new(|| { + let cat: TransientPtr = TransientPtr::new(Cat::new()); - cat + cat + }) }) .await?; diff --git a/examples/with-3rd-party/bootstrap.rs b/examples/with-3rd-party/bootstrap.rs index c5512c4..4fea754 100644 --- a/examples/with-3rd-party/bootstrap.rs +++ b/examples/with-3rd-party/bootstrap.rs @@ -18,7 +18,7 @@ pub fn bootstrap() -> Result, Box> di_container .bind::() - .to_default_factory(&|_| TransientPtr::new(Shuriken::new()))?; + .to_default_factory(&|_| Box::new(|| TransientPtr::new(Shuriken::new())))?; Ok(di_container) } -- cgit v1.2.3-18-g5258