aboutsummaryrefslogtreecommitdiff
path: root/examples/with-3rd-party
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-20 17:40:02 +0200
committerHampusM <hampus@hampusmat.com>2022-08-21 18:17:50 +0200
commit12acab96a7d9ba8032378f8be7b6932f4406a849 (patch)
tree3f162a7d7cad502b89ff76a02293b0f106a57059 /examples/with-3rd-party
parentf9d53a16fe08aedb805c52630d649aa035163edc (diff)
docs: simplify with-3rd-party example
Diffstat (limited to 'examples/with-3rd-party')
-rw-r--r--examples/with-3rd-party/bootstrap.rs13
-rw-r--r--examples/with-3rd-party/ninja.rs6
-rw-r--r--examples/with-3rd-party/third-party-lib/src/lib.rs10
3 files changed, 8 insertions, 21 deletions
diff --git a/examples/with-3rd-party/bootstrap.rs b/examples/with-3rd-party/bootstrap.rs
index e51c104..1ab3192 100644
--- a/examples/with-3rd-party/bootstrap.rs
+++ b/examples/with-3rd-party/bootstrap.rs
@@ -1,7 +1,7 @@
use syrette::errors::di_container::BindingBuilderError;
use syrette::ptr::TransientPtr;
use syrette::{declare_default_factory, DIContainer};
-use third_party_lib::{IShuriken, Shuriken};
+use third_party_lib::Shuriken;
// Interfaces
use crate::interfaces::ninja::INinja;
@@ -9,7 +9,7 @@ use crate::interfaces::ninja::INinja;
// Concrete implementations
use crate::ninja::Ninja;
-declare_default_factory!(IShuriken);
+declare_default_factory!(Shuriken);
pub fn bootstrap() -> error_stack::Result<DIContainer, BindingBuilderError>
{
@@ -18,13 +18,8 @@ pub fn bootstrap() -> error_stack::Result<DIContainer, BindingBuilderError>
di_container.bind::<dyn INinja>().to::<Ninja>()?;
di_container
- .bind::<dyn IShuriken>()
- .to_default_factory(&|| {
- let shuriken: TransientPtr<dyn IShuriken> =
- TransientPtr::new(Shuriken::new());
-
- shuriken
- })?;
+ .bind::<Shuriken>()
+ .to_default_factory(&|| TransientPtr::new(Shuriken::new()))?;
Ok(di_container)
}
diff --git a/examples/with-3rd-party/ninja.rs b/examples/with-3rd-party/ninja.rs
index 945adf0..5b80b36 100644
--- a/examples/with-3rd-party/ninja.rs
+++ b/examples/with-3rd-party/ninja.rs
@@ -1,17 +1,17 @@
use syrette::{injectable, ptr::TransientPtr};
-use third_party_lib::IShuriken;
+use third_party_lib::Shuriken;
use crate::interfaces::ninja::INinja;
pub struct Ninja
{
- shuriken: TransientPtr<dyn IShuriken>,
+ shuriken: TransientPtr<Shuriken>,
}
#[injectable(INinja)]
impl Ninja
{
- pub fn new(shuriken: TransientPtr<dyn IShuriken>) -> Self
+ pub fn new(shuriken: TransientPtr<Shuriken>) -> Self
{
Self { shuriken }
}
diff --git a/examples/with-3rd-party/third-party-lib/src/lib.rs b/examples/with-3rd-party/third-party-lib/src/lib.rs
index f3b3ed3..a5afcec 100644
--- a/examples/with-3rd-party/third-party-lib/src/lib.rs
+++ b/examples/with-3rd-party/third-party-lib/src/lib.rs
@@ -1,8 +1,3 @@
-pub trait IShuriken
-{
- fn throw(&self);
-}
-
pub struct Shuriken {}
impl Shuriken
@@ -12,11 +7,8 @@ impl Shuriken
{
Self {}
}
-}
-impl IShuriken for Shuriken
-{
- fn throw(&self)
+ pub fn throw(&self)
{
println!("Threw shuriken!");
}