aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/prevent-circular/main.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/examples/prevent-circular/main.rs b/examples/prevent-circular/main.rs
index 7e10024..c690a9c 100644
--- a/examples/prevent-circular/main.rs
+++ b/examples/prevent-circular/main.rs
@@ -1,7 +1,10 @@
+//! Example demonstrating the prevention of circular dependencies.
+//!
+//! Having circular dependencies is generally bad practice and is detected by Syrette when
+//! the `prevent-circular` feature is enabled.
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(clippy::disallowed_names)]
-use std::error::Error;
use syrette::di_container::blocking::prelude::*;
use syrette::injectable;
@@ -9,7 +12,7 @@ use syrette::ptr::TransientPtr;
struct Foo
{
- bar: TransientPtr<Bar>,
+ _bar: TransientPtr<Bar>,
}
#[injectable]
@@ -17,13 +20,13 @@ impl Foo
{
fn new(bar: TransientPtr<Bar>) -> Self
{
- Self { bar }
+ Self { _bar: bar }
}
}
struct Bar
{
- foo: TransientPtr<Foo>,
+ _foo: TransientPtr<Foo>,
}
#[injectable]
@@ -31,7 +34,7 @@ impl Bar
{
fn new(foo: TransientPtr<Foo>) -> Self
{
- Self { foo }
+ Self { _foo: foo }
}
}
@@ -42,7 +45,8 @@ fn main() -> Result<(), anyhow::Error>
di_container.bind::<Foo>().to::<Foo>()?;
di_container.bind::<Bar>().to::<Bar>()?;
- let foo = di_container.get::<Foo>()?.transient()?;
+ // The following won't work. Err will be returned.
+ let _foo = di_container.get::<Foo>()?.transient()?;
Ok(())
}